View Full Version : Switching Functions
technochild
09-03-2006, 09:28 AM
Hello All,
I have been doing pretty good on my own with javascript for the past few months, however I have run into a problem that may not have a solution -
I have two identical forms with two completely different javascript functions to process the form. Is there a way to add two radio buttons to switch between the two javascript functions?
<form name="input" action="#" method="post" onsubmit="return function1(this.form)">
<input type="text" name="variable">
</form>
-AND-
<form name="input" action="#" method="post" onsubmit="return function2(this.form)">
<input type="text" name="variable">
</form>
For demonstration purposes let function 1 be function1{} and function 2 be function2{}
Thanks,
-tc
Kravvitz
09-04-2006, 12:10 AM
this.form.onsubmit=function(){return function1(this)}
this.form.onsubmit=function(){return function2(this)}
technochild
09-04-2006, 07:30 AM
would that be like this ?-
<form name="input" action="#" method="post">
<input type="text" name="variable">
<input type="radio" name="sel" this.form.onsubmit="function(){return function1(this)}">
<input type="radio" name="sel" this.form.onsubmit="function(){return function2(this)}">
</form>
Kravvitz
09-04-2006, 11:37 PM
No. You can't just throw JavaScript code in an element's start tag. It needs to be in a script element or in the value of an element's attribute.
Here's the simple way to do it using the inline onclick attribute:
<input type="radio" name="sel" onclick="this.form.onsubmit=function(){return function1(this)}">
<input type="radio" name="sel" onclick="this.form.onsubmit=function(){return function2(this)}">
technochild
09-05-2006, 10:39 AM
Oh, right.... sorry :) Thanks a bunch - I'll try it later today
technochild
09-06-2006, 12:46 PM
For some reason - I still can't get this thing to work right...
<form name="testform" action="#" method="post">
<input name="inputbox" size="20" onkeyup="return handleEnter(this,event)"><br>
<input type="radio" name="sel" onclick="this.form.onsubmit=function(){return function1(this.form)}">Function1<br>
<input type="radio" name="sel" onclick="this.form.onsubmit=function(){return function2(this.form)}">Function2 <input type="submit" value="Go" name="submit">
</form>
EDIT: Oh... I think that it's supposed to be
<input type="radio" name="sel" onclick="this.form.onsubmit=function1(){return function1(this.form)}">Function1<br>
<input type="radio" name="sel" onclick="this.form.onsubmit=function2(){return function2(this.form)}">Function2 <input type="submit" value="Go" name="submit">
:rolleyes:
EDIT: Nope... that doesn't seem to work either
Kravvitz
09-07-2006, 01:29 AM
*shrugs* Looks fine to me.
Perhaps if you showed us more of your code we would see the problem.
technochild
09-11-2006, 10:39 AM
Sorry for replying this late, I have been gone... Thank you for all your help Kravvitz, I ended up using a php include function to change the onSubmit of the form. This way, there was no selection to be made and it was automatically selected by the previous page.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.