SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jun 2006
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    getting the name of the submit button using js

    <form name="f1" method="post" onsubmit="get_button()">

    <input type="submit" name="s1" value="s1">
    <input type="submit" name="s2" value="s2">
    <input type="submit" name="s3" value="s3">

    </form>

    on submit I want to know which submit button I clicked. How to get it.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is one way:
    Code:
    <script type="text/javascript">
    var theClickedButton;
    </script>
    ...
    <input type="submit" name="s1" value="s1" onclick="theClickedButton=this.value;return true;" />
    <input type="submit" name="s2" value="s2" onclick="theClickedButton=this.value;return true;" />
    ...
    Then when onsubmit fires, you have the value of the clicked submit button in the global variable theClickedButton.

  3. #3
    SitePoint Addict
    Join Date
    Jun 2006
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx jimfraser...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •