www.webdeveloper.com
Results 1 to 2 of 2

Thread: Getting the value of a submit button

  1. #1
    Join Date
    Nov 2011
    Posts
    1

    Getting the value of a submit button

    How do I get the value of a submit button put into a global variable onclick?

    <input type="submit" value="2">


    How would I get the value of "2" to say a variable named subVal?

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    The submit button sends the coordinates of the mouse when you click that button, so that you may use a trick based on a hidden input:
    Code:
    <script type="text/javascript">
    function addValue(f){
    f['subVal'].value=f['sub'].value;
    }
    </script>
    Code:
    <form action="" onsubmit="return addValue(this)">
    <input type="submit" value="2" name="sub">
    <input type="hidden" name="subVal">
    ...
    </form>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles