/    Sign up×
Community /Pin to ProfileBookmark

On Submit – Two Scripts to be verified

Hi,

Before I start…yes, I know there are scripts that can do both things. But I prefer to use two becuase…the scripts are easy to understand.

With that out of the way…

I have a form…that is controlled by two scripts

1) First script verifies that all required fields are filled in.

2) Second script ensures the e-mail entered is of the correct format.

Now the trouble I’m having is that in order to activate both scripts, I’m required to add a “onSubmit return…” code to the form. Once the form is submitted…the scripts activate and check to see if all is okay.

<form method=POST action=”http://www.my-domain.com/cgi-bin/formmail.pl” onSubmit=”return checkEmail(this), checkrequired(this)”>

However, if i fill in all the fields that need to be filled in, leave the e-mail address field blank and then click submit…a notice should come up saying that the e-mail is inccorect – so the form cannot be submitted.

BUT…this does not happen…the form is submitted.

In summary…the e-mail script is not activated when the conditions for the other script are met (it does work the other way though).

I am guessing this has to do with the…onSubmit=”return checkEmail(this), checkrequired(this)”…coding.

Is it not possible to have two scripts checked at the sametime?

One final thing…both scripts do work…I’ve tested both individually. Just not together.

Sorry for the long explanation..I hope I havn’t confused you.

Thanks for any help.

Riz

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@javaNoobieOct 14.2004 — onsubmit="if(checkEmail(this)){return checkRequired(this);}else{return false;}"
EDIT: Best way out of this will be to combine both scripts though.

A look through the one line code with proper spacing, indentation and comments:
<i>
</i>if(checkEmail(this)){ //if email is valid go to next checking script
return checkRequired(this); //will return true or false depending on the success of the form
}else{ //if email is invalid, return false;
return false;
}
Copy linkTweet thisAlerts:
@riz-manauthorOct 14.2004 — Thanks for the reply. I don't wish to be a pain but how would you combine these two scripts (I know what to add...just not what to delete):

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

function checkEmail(myForm) {

if (/^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/.test(myForm.email.value)){

return (true)

}

alert("Invalid E-mail Address! Please re-enter.")

return (false)

}

// End -->

</script>

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

function checkrequired(which) {

var pass=true;

if (document.images) {

for (i=0;i<which.length;i++) {

var tempobj=which.elements[i];

if (tempobj.name.substring(0,8)=="required") {

if (((tempobj.type=="text"||tempobj.type=="textarea")&&

tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&

tempobj.selectedIndex==0)) {

pass=false;

break;

}

}

}

}

if (!pass) {

shortFieldName=tempobj.name.substring(8,30).toUpperCase();

alert("Please make sure the "+shortFieldName+" field was properly completed.");

return false;

}

else

return true;

}

// End -->

</script>



Also, what would the script be called when I need to call it:



onSubmit= return "?????"



Thanks for any help given.



Riz
Copy linkTweet thisAlerts:
@javaNoobieOct 15.2004 — <i>
</i>function checkRequired(which){
var pass=true;
var errMsg = '';
if (document.images) {
for (i=0;i&lt;which.length;i++) {
var tempobj=which.elements[i];
if (tempobj.name.substring(0,8)=="required") {
if (((tempobj.type=="text"||tempobj.type=="textarea")&amp;&amp;tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&amp;&amp;tempobj.selectedIndex==0)){
shortFieldName=tempobj.name.substring(8,30).toUpperCase();
errMsg += '-Please make sure the "+shortFieldName+" field was properly completed.n'
pass=false;
}
}
}
}
if (/^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/.test(myForm.email.value)){
errMsg += '-Invalid email';
pass = false;
}
if(!pass){alert(errMsg);}
return pass;
}
change your onsubmit toonsubmit="return checkRequired(this)"
×

Success!

Help @riz-man 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.19,
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,
)...