Simulating a button click

Discussion in 'Javascript' started by Wojtek, Mar 28, 2007.

  1. Wojtek

    Wojtek Guest

    Given the following somewhat abbreviated code:
    ------------------------------------------
    <table>

    <form name="aForm1" action="doStuff" method="post">
    <input type="hidden" name="id" value="1">
    <tr onClick="aForm1.myButton.value='View'; aForm1.submit();">
    <td>
    <input type="submit" name="myButton" value="View">
    <input type="submit" name="myButton" value="Edit">
    </td>
    <td>Value 1</td>
    </tr>
    </form>

    <form name="aForm2" action="doStuff" method="post">
    <input type="hidden" name="id" value="2">
    <tr onClick="aForm2.myButton.value='View'; aForm2.submit();">
    <td>
    <input type="submit" name="myButton" value="View">
    <input type="submit" name="myButton" value="Edit">
    </td>
    <td>Value 2</td>
    </tr>
    </form>

    </table>
    ------------------------------------------

    If I click on the View button, then the form gets submitted, and the
    form handler reads that the value of myButton as 'View"

    But if I click on the row, then no value for the myButton gets passed
    to the form handler.

    I did try aForm1.myButton[0].value='View'

    How do I get the form submit to set the passed value of myButton to
    'View'?

    --
    Wojtek :)
    Wojtek, Mar 28, 2007
    #1
    1. Advertising

  2. Wojtek

    Wojtek Guest

    Michael White wrote :

    > ... onclick="document.aForm1.myButton.value= 'View' ">


    Yes, I do have the 'document.' before each element call. I trimmed it
    from the example because it causes a word wrap, and it is more readable
    without the word-wrap :)

    --
    Wojtek :)
    Wojtek, Mar 28, 2007
    #2
    1. Advertising

  3. Wojtek

    Wojtek Guest

    Wojtek wrote :

    Hmmm, just read the HTML spec on buttons.

    The HTML spec states that if a form has multiple buttons, then only the
    clicked button's value will be processed and sent to the CGI.

    So if NO button is clicked by the user, then no button value is sent to
    the CGI.

    I would prefer not to use a hidden field for a shadow button value as
    that adds another thing to be proccessed by the CGI. And it is not
    "elegant" enough....

    --
    Wojtek :)
    Wojtek, Mar 28, 2007
    #3
    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. Purvi T
    Replies:
    0
    Views:
    821
    Purvi T
    Oct 19, 2004
  2. CW
    Replies:
    11
    Views:
    1,318
    Steven Cheng[MSFT]
    Oct 15, 2004
  3. Amy
    Replies:
    0
    Views:
    960
  4. Alhambra Eidos Kiquenet

    POST to another page simulating click

    Alhambra Eidos Kiquenet, Feb 13, 2008, in forum: ASP .Net
    Replies:
    3
    Views:
    2,085
    Cowboy \(Gregory A. Beamer\)
    Feb 13, 2008
  5. Replies:
    0
    Views:
    118
Loading...

Share This Page