How to pass 2 parameters with OnClick?

Z

Zalek Bloom

Hello,

Here is my problem:
I am displaying to a user a row of buttons. Depending on which button
user presses, I want to go to a different URL and to give a different
value to a hidden variable.

My code is:
<FORM NAME=FORM1 ACTION="">
<input type="button" name="B1" onclick="ModC('1')">
<input type="button" name="B2" onclick="ModC('2')">
<input type="button" name="B3" onclick="ModC('3')">

<input type="hidden" name="property_key" value="0">


function ModC(a)
document.form1.property_key.value = a
document.form1.submit()
End Function

Now, I want also to change ACTION parm on the FORM, so depending on
some calculation ACTION=MODIFY.ASP or ACTION=SHOW.ASP

I tried:
<input type="button" name="B1"
onclick="document.form1.action ='MODIFY.ASP' ; ModC('1')">

this didn't work. Any ideas how to solve this problem?

Thanks,

Zalek
 
J

Jim

You can set the action property for a form within a javascript function,
then submit the form. Hope the following helps

jim cant

function handleClick( form )
{
form.action = "yourDesiredPage.jsp";
form.submit();
}
.....
<form name="theForm" action="DONT_CARE" method="POST" >
.....
<input type="button" onclick=handleClick(this.form)
value="ClickHere" />
</form>
.....
 
R

Roland Hall

Zalek...

I took the form you had, except I put values on the buttons, and I rewrote
the script. I performed a calculation to check if a is odd or even, which
tells me which button was clicked, by using the vbscript command MOD with a
value of 2. If it returns a 1 (odd), then I set the action of the form to
modify.asp. If it returns a 0 (even) then I set the action to view.asp.

Remove the alerts. Remove the comment tags in the script to submit the form
and set the return to true.
Perhaps this will give you some ideas to get your script working the way you
want it to.

http://kiddanger.com/lab/form0.html

Hello,

Here is my problem:
I am displaying to a user a row of buttons. Depending on which button
user presses, I want to go to a different URL and to give a different
value to a hidden variable.

My code is:
<FORM NAME=FORM1 ACTION="">
<input type="button" name="B1" onclick="ModC('1')">
<input type="button" name="B2" onclick="ModC('2')">
<input type="button" name="B3" onclick="ModC('3')">

<input type="hidden" name="property_key" value="0">


function ModC(a)
document.form1.property_key.value = a
document.form1.submit()
End Function

Now, I want also to change ACTION parm on the FORM, so depending on
some calculation ACTION=MODIFY.ASP or ACTION=SHOW.ASP

I tried:
<input type="button" name="B1"
onclick="document.form1.action ='MODIFY.ASP' ; ModC('1')">

this didn't work. Any ideas how to solve this problem?

Thanks,

Zalek
 
R

Roland Hall

"which button was clicked" should read which button of which group was
picked (odd or even) button 1 and 3 = odd, etc.

Zalek...

I took the form you had, except I put values on the buttons, and I rewrote
the script. I performed a calculation to check if a is odd or even, which
tells me which button was clicked, by using the vbscript command MOD with a
value of 2. If it returns a 1 (odd), then I set the action of the form to
modify.asp. If it returns a 0 (even) then I set the action to view.asp.

Remove the alerts. Remove the comment tags in the script to submit the form
and set the return to true.
Perhaps this will give you some ideas to get your script working the way you
want it to.

http://kiddanger.com/lab/form0.html

Hello,

Here is my problem:
I am displaying to a user a row of buttons. Depending on which button
user presses, I want to go to a different URL and to give a different
value to a hidden variable.

My code is:
<FORM NAME=FORM1 ACTION="">
<input type="button" name="B1" onclick="ModC('1')">
<input type="button" name="B2" onclick="ModC('2')">
<input type="button" name="B3" onclick="ModC('3')">

<input type="hidden" name="property_key" value="0">


function ModC(a)
document.form1.property_key.value = a
document.form1.submit()
End Function

Now, I want also to change ACTION parm on the FORM, so depending on
some calculation ACTION=MODIFY.ASP or ACTION=SHOW.ASP

I tried:
<input type="button" name="B1"
onclick="document.form1.action ='MODIFY.ASP' ; ModC('1')">

this didn't work. Any ideas how to solve this problem?

Thanks,

Zalek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top