PDA

View Full Version : nested functions in onSubmit command


nickelsto
08-09-2002, 12:27 AM
As the subject suggests, I want to perform more than one function when I submit my form. Below is the code I currently have written.

In the form tag, I have onSubmit="return submitIt()", which then performs the test, and then does "validate()", and then also does the "openThanks()" function. However once the email test is complete, the program repeats the submitIt() function over and over again. I think that this is because there is no "return true" line after the if statement. But I tried it by adding the "return true" line and the function did not continue to the "validate" function.

Am I on the right track, trying to nest the functions in this manner, or should I toss this and go back to the drawing board? And if this is the right track, what can I do with the first function so that once the test is done, it will continue on to the second function, and then on to the third (openthanks) function without repeating the submitIt() function?

Thank you to whomever may decide to help me with this.

<script>

re=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/

function submitIt(order){
if(re.test(order.email.value)){
validate()
}
alert("Invalid email address")
order.email.focus()
order.email.select()
return false
}


function validate() {
if ((document.order.name.value=="")||(document.order.email.value=="")||(document.order.account.value==""))
{
alert ("You must fill in all of the required fields!")
return false
}
else
{
openThanks()
return true
}
}

function openThanks() {
ThanksWindow=window.open("thxo.htm",
"thxWin","width=432,height=180")
ThanksWindow.focus()
}

adios
08-09-2002, 01:02 AM
onSubmit="return submitIt()"

...and:

function submitIt(order){

...don't match up; you forgot to pass the Form object.
No nested functions, just stacked ones...

function submitIt(order){
if (re.test(order.email.value)) {
return validate();

beetle
08-09-2002, 08:08 AM
*** WARNING!! SHAMELESS PLUG AHEAD! ***

Skip all that mess and use my validator (http://www.peterbailey.net/jsdemo) :D

nickelsto
08-09-2002, 08:24 AM
That worked perfect, thanks for your help, i really appreciate it.