
Solid, safe website tools.
Whatever your need, Will Bontrager builds powerful software solutions.
|
(Get Attention Ticker for your web site)
Multiple Function Calls with One Onclick AttributeBy Will Bontrager This question comes up from time to time. And the methods I've seen on the Internet are a bit short of complete. The question is, "How do I run more than one JavaScript function with one onclick= or onsubmit= call?" and variations thereof. The technique is the same whether the attribute is onclick or onsubmit. Let's suppose these functions need to run when a submit button is clicked: One() Two() Three() Four() The methods I've seen on the Internet would suggest making a new function that calls each function, in turn. Then, call that new function with the onsubmit attribute. Example: Then, call the DoAllThese() function with this attribute value: It works just fine in many instances image tag onclick attributes, link onclick attributes, and some form field onclick attributes.
A lack is observed when a false return value of any of the functions needs to abort form processing. For that functionality, the modified DoAllThese() function returns the value of the first function that returns a value of false. If none of the functions return a value of false, then DoAllThese() returns the value of the last function it called. Here is the modified DoAllThese() function: The onclick attribute's value is modified accordingly: Now, sleep well :) January 27, 2007 Please note: Articles on this website are presented "as is". However - If you have a question about a CGI script, HTML, CSS, PHP, or JavaScript
Rate this blog post.
No page reload! |
|
|
© 1998-2001 William and Mari Bontrager |
|