By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,028 Members | 1,733 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,028 IT Pros & Developers. It's quick & easy.

How to pass 2 parameters with OnClick?

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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>
.....

"Zalek Bloom" <Za********@hotmail.com> wrote in message
news:mu********************************@4ax.com...
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

Jul 20 '05 #2

P: n/a
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

"Zalek Bloom" <Za********@hotmail.com> wrote in message
news:mu********************************@4ax.com...
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
Jul 20 '05 #3

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

"Roland Hall" <nobody@nowhere> wrote in message
news:O%****************@tk2msftngp13.phx.gbl...
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

"Zalek Bloom" <Za********@hotmail.com> wrote in message
news:mu********************************@4ax.com...
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

Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.