-3

How to findout which button is clicked.

`<input type="submit" name="quest" id="ques" value="quest" />
<input type="submit" name="answer" id="ans" value="answer"  />`
ShuklaSannidhya
  • 8,572
  • 9
  • 32
  • 45
tweety
  • 11
  • 5

2 Answers2

1

Its easy you can code like i did

Code:

<html>
   <head>
      <script language="javascript">         
         function checkBtn(event) {
               alert(event.target.name);
         }
      </script>


   </head>
   <body>
      <br /><br />
      <form action="multiSubmit.php" method="post" onSubmit="return false;">
         <input type="submit" name="quest" id="quest" value="quest" onClick="checkBtn(event)" /><br />
         <input type="submit" name="answer" id="answer" value="answer" onClick="checkBtn(event)" /><br />
      </form>

   </body>
</html>
Vishal Bharti
  • 185
  • 1
  • 9
0

Code should look like below

<script language="javascript">         
   function checkBtn(event) {
         alert(event.target.name);
     }
</script>

Add a onClick="checkBtn(event)" to your every Button. Else you can add a onsubmit to your form like this onSubmit="checkBtn(event)"

Techie
  • 44,706
  • 42
  • 157
  • 243
  • But by clicking the question and answer button, I have two seperate forms. So, I've to write seperate conditions for both buttons within one validate function.Is it possible to write. Please tell me. – tweety Feb 07 '13 at 07:49
  • within the checkBtn function you can write whatever you want and submit the correct form as you want – Techie Feb 07 '13 at 07:50
  • read this for form submit. http://www.javascript-coder.com/javascript-form/javascript-form-submit.phtml – Techie Feb 07 '13 at 07:52