...

View Full Version : Rrunning two onSubmit's at once?



angst
07-05-2005, 07:07 PM
hello, i'm trying to run both of these form validation scripts at once while submitting a form, but only the first one (email validate) seems to be working,
the other is for confirming password.

my code:


<script language = "Javascript">

function echeck(str) {

var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
alert("Please Enter a Valid E-mail Address")
return false
}

if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Please Enter a Valid E-mail Address")
return false
}

if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("Please Enter a Valid E-mail Address")
return false
}

if (str.indexOf(at,(lat+1))!=-1){
alert("Please Enter a Valid E-mail Address")
return false
}

if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
alert("Please Enter a Valid E-mail Address")
return false
}

if (str.indexOf(dot,(lat+2))==-1){
alert("Please Enter a Valid E-mail Address")
return false
}

if (str.indexOf(" ")!=-1){
alert("Please Enter a Valid E-mail Address")
return false
}

return true
}

function ValidateForm(){
var emailID=document.profile.email

if ((emailID.value==null)||(emailID.value=="")){
alert("Please Enter your Email Address")
emailID.focus()
return false
}
if (echeck(emailID.value)==false){
emailID.value=""
emailID.focus()
return false
}
return true
}
</script>


<form name="profile" action=signup.php method=post onSubmit="return ValidateForm()" onsubmit="return checkForSamePassword(this)">


anyone tell me what i've done wrong or need to do to fix this?

thanks in advance for your time!
-Ken

Burgerking63
07-05-2005, 07:17 PM
onSubmit="return ValidateForm(); return checkForSamePassword(this)">

SpirtOfGrandeur
07-05-2005, 07:23 PM
onSubmit="return (ValidateForm() && checkForSamePassword(this) )">

angst
07-05-2005, 07:24 PM
still having the same problem, only seems to run the first called function.



<form name="profile" action=signup.php method=post onsubmit="return checkForSamePassword(this); return ValidateForm()">


any other ideas?

thanks again for your time!
-Ken

angst
07-05-2005, 07:25 PM
oh thanks SpirtOfGrandeur!
that did the trick!

-Ken

GO ILLINI
07-05-2005, 08:49 PM
you could also make a function that calls both functions

like


function functiontocallinonsubmit() {
functiontocall1()
functiontocall2()
}

kenerly
12-24-2005, 07:50 PM
I tried this method above.

onSubmit="return (ValidateForm() && checkForSamePassword(this) )">

But it is by passing all the javascript.
The url is http://christiangamers.net/TS/TS.php

My code

<form name="validation" onSubmit="return checkbae() && return checkCheckBox(this) )" form action="terms.php" method="post">
<table width="380" border="0" align="center">
<tr>
<td width="146" class="style6 gen">Player Name:</td>
<td width="224"><input type="text" name="name" /></td>
</tr>
<tr>
<td><span class="style6 gen">Email</span><span class="gen">:</span></td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td><input type="checkbox" value="0" name="agree"></td>
<td class="style6 gen">Do you accept these terms?</td>
</tr>
<tr>
<td><input name="submit" type="submit" value="Agree" /></td>
<td>&nbsp;</td>
</tr>
</table>
<p align="center" class="gen">script by <a href="http://www.christian-web-masters.com" target="_blank">iLuke</a> </p>
</form>


<script language="JavaScript1.2">

//Advanced Email Check credit-
//By JavaScript Kit (http://www.javascriptkit.com)
//Over 200+ free scripts here!

var testresults
function checkemail(){
var str=document.validation.email.value
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{
alert("Please input a valid email address!")
testresults=false
}
return (testresults)
}
</script>


<script>
function checkbae(){
if (document.layers||document.getElementById||document.all)
return checkemail()
else
return true
}
</script>


<script language=JavaScript>
<!--

//Accept terms & conditions script (by InsightEye www.insighteye.com)
//Visit JavaScript Kit (http://javascriptkit.com) for this script & more.

function checkCheckBox(f){
if (f.agree.checked == false )
{
alert('Please check the box to continue.');
return false;
}else
return true;
}
//-->
</script>

Pyth007
12-27-2005, 03:29 PM
onSubmit="return (ValidateForm() && checkForSamePassword(this) )">
... and ...
<form name="validation" onSubmit="return checkbae() && return checkCheckBox(this) )" form action="terms.php" method="post">

The first method was correct; the second as typed inside the <form> tag is incorrect. Notice that in the former method, you are only calling 'return' once and return the value of ValidateForm() and checkForSamePassword(). Thus the second should be written:

<form name="validation" onSubmit="return (checkbae() && checkCheckBox(this) )" action="terms.php" method="post">

Also, inside your <form> tag, you had an extra 'form' attribute(?) which may be causeing some confusion to the browsers (although the browsers should just be ignoring attributes they don't understand).

kenerly
12-27-2005, 05:28 PM
Thanks Pyth007 that makes more sense...:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum