Click to See Complete Forum and Search --> : form onsubmit


florida
03-28-2003, 10:05 AM
Please advise how I would call two functions in my form submit?

My attempt:

<FORM name="myname" action="myname_add.cfm" method="POST" enablecab="Yes" onsubmit="return functionOne();return functionTwo">

DaiWelsh
03-28-2003, 10:12 AM
I think the problem lies in the fact that you are trying to return both function results. When you say return functionOne(); the result of functionOne will be returned as the result of the onsubmit action and the second part will not run.

onsubmit="functionOne();functionTwo();">

will run both, if you need the result of both functions to determine whether the form submits or not then you could do it with some if syntax inline but it would be easier to read if you create a third function that calls the two functions and checks their return results then decides what to return overall.

HTH,

Dai

Phil Karras
03-28-2003, 02:16 PM
Make a third function that calls the other two and returns one result.

Then call the third function with your onSubmit.

florida
03-28-2003, 04:04 PM
Would it be like this?



functionOne
{
//stuff here
}

functionTwo
{
//stuff here
}

functionThree
{
functionOne();
functionTwo();
}

<FORM name="myname" action="myname_add.cfm" method="POST" enablecab="Yes" onsubmit="return functionThree();">

Phil Karras
03-29-2003, 10:29 AM
Close but in your function three you forgot to return a value to use in the onSubmit="return Three();" - if Three returns nothing you'll either never submit the form or you will always submit the form no matter what.

functionThree {
var Rtn = true;

Rtn = functionOne();

if (Rtn) { // Still true? then check here too
Rtn = functionTwo();
}

return Rtn;
}

or something like that.