/    Sign up×
Community /Pin to ProfileBookmark

validation fail after auto-submit

i have a validation code in the head section :
<script>

function valid() {

var Form;
Form = document.MyForm;

if (Form.MyField.value.length == 0) {
alert(“The field MyField is required !”);
Form.MyField.focus();
return (false);
}

}
</script>

and an auto-submiting code required to return data from the server:

<SCRIPT LANGUAGE=”JavaScript”>
function do_submit()
{
document.MyForm.action=”<? echo $_SERVER[‘PHP_SELF’];?>”;
document.MyForm.submit();
}

<script>

if i do fill all the required fields and choose any field that calls the do_submit() function, all the fields below these field remain with a value selected (as it was previously filled) but the javascript valid() function, (callled when the submit button is hitted) do the validation for these already filled fields as it was empty but they are not .

How can i fix it? i try to return true at the end of the valid function… window.focus on the do_submit function but it do not work …

thank´s in advance

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@steelersfan88Apr 12.2004 — why not do the validation and all the rest in the dosubmit function? Use something like:[code=php]function do_submit() {
if(valid()) {
document.MyForm.action="<? echo $_SERVER['PHP_SELF'];?>";
return true;
}
return false;
}[/code]
Copy linkTweet thisAlerts:
@amrigoauthorApr 13.2004 — great i will try
Copy linkTweet thisAlerts:
@steelersfan88Apr 13.2004 — give it go, and tell me what else you'll need, and whether or not you got it working ?
Copy linkTweet thisAlerts:
@amrigoauthorApr 14.2004 — i need to do 4 self submits before

submit to the real next file

and have 14 fields to validate

how can i concatenate these validations inside the submit function ?
×

Success!

Help @amrigo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...