[thelist] JS: test which submit button was clicked.

jsWalter jsWalter at torres.ws
Fri Jun 4 13:17:26 CDT 2004


1) you can have multiple SUBMITs with the same name.
   Gets a bit hairy, but...

2) I modified your example to produce what your looking for


   <script language='JavaScript' type='text/javascript'>
      var $subName = '';

      function TestRejection()
      {
         if ($subName == 'Reject')
            return confirm('Are you sure you want to reject this
item?');

         else
            return true;
     }

      function whichHit ( $objSubmit )
      {
         $subName = $objSubmit.value;
      }

   </script>

      <html>
      <head>
         <title>Untitled</title>
      </head>

      <body>

      <form name="FormName"
            onSubmit="TestRejection();"
            action=""
            method="post">

         <input type="submit" id="a" name="WhatToDo" value="Approve"
onclick="whichHit(this)">
         <input type="submit" id="b" name="WhatToDo" value="Reject"
onclick="$subName = this.value">

      </form>


Now notice, the SUBMIT tags are different.

I did it 2 ways so you could decide which you wanted to do.

Both have the same NAME, but each has a different ID.

The first calls a function onClick, the second directly assigns its name
to a var.

Both ultimately do the same thing.

Hope this helps.

Walter






More information about the thelist mailing list