Which button is clicked

by "Derek Lavine" <derek(at)realware.com.au>

 Date:  Wed, 7 Mar 2001 10:26:32 +1000
 To:  <hwg-languages(at)hwg.org>
 References:  hotmail
  todo: View Thread, Original
Hi all,

I must first appologies as I have asked part of this question before but
seem to have lost the answer (I think provided by Cyanide_7)

If I have a form with an onSumbit event handler specified. How do I, from
with in the event handler, determine which button was clicked to trigger the
submit event

Viz

<form action="dothis.html" onSubmit="return checkForm(this)" method="post">
<input type="text" name="field1">
<input type="text" name="field1">
<input type="submit" name="action1" value="Do this">
<input type="submit" name="action2" value="Don't do this">
<input type="image" name="image1" value="blah" src="pic1.gif" >
<input type="image" name="image2" value="blah blah" src="pic2.gif" >

</form>

How inside the checkForm() function do I determine which of the two submit
buttons was clicked or which of the images was clicked. I realise I can do
something using an onclick event handler on each of the submit buttons or
iamges but this seems a little awkward and long winded.


What about if I use <a> within a form tag eg

<form action="dothis.html" onSubmit="return checkForm(this)" method="post">
<input type="text" name="field1">
<input type="text" name="field1">
<a href="##" onclick="document.forms[0].submit()">This does not work</a>
</form>

is there anyway to cause the form fields to be submited and request the
dothis.html page as though a submit button on the form was clicked.

One last thing is there away I can change the onSubmit event handler on a
form. I have tired
document.forms[0].onSubmit=newHandler;

Thanks for your time and help (I promise not to lose the answers this time)

Cheers
Derek

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA