detecting which <button> was pressed

liunx

Guest
hi<br />
<br />
Until now I've always used the <input type='submit'> control to submit forms, but I now must use 'images as buttons' so must use the <button></button> element. The site is private and the only browser in use will be IE 5.5 or later.<br />
<br />
Question is simple - if I have more than one <button> per form, how do I detect which button was pressed? It seems that all name/value pairs for the buttons are sent to the server just as most <input>s are (except unchecked boxes and unpressed submits and others possibly), regardless of which was clicked. <br />
<br />
Example:<br />
<br />
<form action='x.asp' method='get'><br />
<button name='submit' type='submit'>x</button><br />
<button name='submit' type='submit'>y</button><br />
<button name='submit' type='submit'>z</button><br />
</form><br />
<br />
Clicking any of these and then viewing the resulting querystring sent to the server, we get:<br />
<br />
.../target.asp?submit=x&submit=y&submit=z<br />
<br />
So, how can I tell which was pressed? I've got a feeling this is some microsoft thing cause they also implement the value sent to the server stangely, sending the innerText (e.g. x, y and z) rather than an explicit value attribute (not included above). <br />
<br />
Could be me missing something obvious though.<!--content-->you will need to name them different. if you are using buttons tehn they don't have to be submit. a button is usually done by javascript so it doesn't need to be submit, beside the form won't notice the buttons.<br />
<br />
<form action='x.asp' method='get'> <br />
<button name='x' type='submit'>x</button> <br />
<button name='y' type='submit'>y</button> <br />
<button name='z' type='submit'>z</button> <br />
</form><!--content-->
 
Back
Top