Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
How would I process 2 'onSubmit's?
Old 09-19-2004, 03:14 AM How would I process 2 'onSubmit's?
Yizit's Avatar
Experienced Talker

Posts: 44
Location: CT
Trades: 0
Hi,

I have 2 javascript routines, one internal (in the <body> area) and the other external (included in the <head> area). Both require that I call them by using 'onSubmit'. I've tried various ways of combing the functions into one call but nothing works. And I can't seem to find any documentation that deals with such a situation.

Run independently they both work fine.

Does anybody have any idea as to how (or if) this can be done?

Appreciate any help.

--Yizit
Yizit is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-19-2004, 08:45 AM
ejumblesale's Avatar
Extreme Talker

Posts: 240
Location: Kent
Trades: 0
You wont be able to have two functions which work independantly with the same name... I would suggest changing the function name of one of them, or if you really want the same name you can have one of the functions accept a variable such as:

onSubmit(form) this will then make a different fuction, however it is really pointless doing it this way and you should just change one of the function names. IT doesnt matter where the JavaScript is in the header, imported or in the body, the functions and variables can still override each other which it is doing in this case.
__________________

Please login or register to view this content. Registration is FREE
- The Internet Jumble Sale,

Please login or register to view this content. Registration is FREE
- Personal space containing interesting articles and information on downloadable scripts

Please login or register to view this content. Registration is FREE
- Free link exchange directory and PPC advertising scheme

Please login or register to view this content. Registration is FREE
- The ejumblesale forums
ejumblesale is offline
Reply With Quote
View Public Profile Visit ejumblesale's homepage!
 
Old 09-19-2004, 08:46 AM
ejumblesale's Avatar
Extreme Talker

Posts: 240
Location: Kent
Trades: 0
Another solution is to nest if else statements in the function ie:

function onSubmit(form)
{
if(form=="form1")
{
//import first function here
}
else
{
//import second function here
}
}

when you call the function you will have to supply the form type ie:
onClick="onSubmit('form1');"
__________________

Please login or register to view this content. Registration is FREE
- The Internet Jumble Sale,

Please login or register to view this content. Registration is FREE
- Personal space containing interesting articles and information on downloadable scripts

Please login or register to view this content. Registration is FREE
- Free link exchange directory and PPC advertising scheme

Please login or register to view this content. Registration is FREE
- The ejumblesale forums

Last edited by ejumblesale; 09-19-2004 at 08:48 AM.. Reason: pressed enter accidently
ejumblesale is offline
Reply With Quote
View Public Profile Visit ejumblesale's homepage!
 
Old 09-19-2004, 01:06 PM
Yizit's Avatar
Experienced Talker

Posts: 44
Location: CT
Trades: 0
Hi,

Thanks for for your reply.

The 2 functions already had different names... one named Blank_TextField_Validator() and the other named validate(). The first, just by reason of its name, is obvious while the second checks another text field in the same form for proper format.

But when I try to call the functions with 2 'onSubmit' entries, such as the following, only the first one will work.

Code:
<form METHOD=POST ACTION="contact_form.php" name="contact" onSubmit="return Blank_TextField_Validator()" onSubmit="return validate()">
I tried various ways of concatenating the 2 onSubmit calls but nothing that I tried worked. So I'm not sure if concatenation is not allowed or I'm not presenting the proper syntax.

I am toying with the idea of having one function call the other or maybe nesting the 2 functions but since I have very little experience with javascript, I've yet to be successful.

I'll keep plugging away at it but any and all ideas are sincerely appreciated.

--Yizit
Yizit is offline
Reply With Quote
View Public Profile
 
Old 09-19-2004, 04:45 PM
Extreme Talker

Posts: 160
Trades: 0
You can only return once to an event handler and the browser will behave appropriately depending on whether the return value is true or false.
It would be better to merge or nest the functions.
Alternatively, you could use another event handler on the submit button itself:

<form onSubmit="return val1();" action="somefile.tcl">
<input onClick="return val2();" type="submit">
</form>

The browser would only look at the val1 function if val2 returned true.

HTH
ElectricSheep is offline
Reply With Quote
View Public Profile
 
Old 09-19-2004, 09:15 PM
Yizit's Avatar
Experienced Talker

Posts: 44
Location: CT
Trades: 0
Hi ejumblesale & ElectricSheep,

Wanted to thank you both for your help and suggestions. I did manage to find a way to combine the 2 functions into 1. What really helps is the time that's saved by not continuing down blind alleys when one finds out what won't work.

Thanks again guys!

--Yizit
Yizit is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How would I process 2 'onSubmit's?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.35284 seconds with 12 queries