Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

doble onsubmit methods 1

Status
Not open for further replies.

WebRic

Technical User
Sep 21, 2004
95
0
0
GB
Is it possible to run two consecutive onsubmit methods on a form?

Would sopmething like this be OK?

<form name="register" action="register.cfm" method="post" onsubmit="return something(this);return othersomething(this)">

Thanks,

R
 
[1] If there are _no_ material side-effect scripted into the functions, you can do this.
[tt]
<form name="register" action="register.cfm" method="post" onsubmit="return something(this) && othersomething(this)">
[/tt]
[2] If there are material side-side scripted into them and you don't want to miss them, you can do this.
[tt]
<form name="register" action="register.cfm" method="post" onsubmit="var x=something(this); var y=othersomething(this); return x && y;">[/tt]
 
I'd suggest something like:

Code:
return (something(this) && othersomething(this));">

That way if one return value was false, the expression would return false, and both would have to return true for the form to be submitted.

Lee
 
Amendment

[2-correction] My posting is incorrect. I would rather suggest this if the premises there are valid. (If there are alerts inside, then it would be annoying. It still not seems perfect. Maybe it is over-worked. Keep it simple then use [1])
[tt]
<form name="register" action="register.cfm" method="post" onsubmit="return something(this)&&othersomething(this) || othersomething(this)&&something(this)">
[/tt]
 
Lee, I still do not get the point in [2] I want to convey properly. Maybe I would go with a version not in-line like the above. It would then be free from undesirable effect as mention. Sorry!

[2-bis]
[tt]<form name="register" action="register.cfm" method="post" onsubmit="return combined(this)">
[/tt]
with the function combined(obj) defined apart.
[tt]
function combined(obj) {
var x=something(obj);
var y=othersomething(obj);
return x && y;
}
[/tt]
 
I agree that if the onsubmit handler is more complex than a couple of return values, it would be best handled in a separate function like you showed. I personally would use a separate function if making more than one evaluation, as your example shows. That would make things easier to read and separate the programming from the HTML code better.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top