How to pass 2 parameters with OnClick?

Discussion in 'Javascript' started by Zalek Bloom, Nov 4, 2003.

  1. Zalek Bloom

    Zalek Bloom Guest

    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
    Zalek Bloom, Nov 4, 2003
    #1
    1. Advertising

  2. Zalek Bloom

    Jim Guest

    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" <> wrote in message
    news:...
    > 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
    Jim, Nov 5, 2003
    #2
    1. Advertising

  3. Zalek Bloom

    Roland Hall Guest

    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" <> wrote in message
    news:...
    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
    Roland Hall, Nov 5, 2003
    #3
  4. Zalek Bloom

    Roland Hall Guest

    "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%...
    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" <> wrote in message
    news:...
    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
    Roland Hall, Nov 5, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AAaron123
    Replies:
    7
    Views:
    3,688
    AAaron123
    Aug 21, 2009
  2. junk.rail
    Replies:
    1
    Views:
    650
    junk.rail
    Jun 30, 2010
  3. bob
    Replies:
    3
    Views:
    175
  4. Replies:
    2
    Views:
    240
  5. Replies:
    4
    Views:
    165
Loading...

Share This Page