[jQuery] Re: which submit button was clicked?

2009-09-15 Thread bjorsq


Hi,

As far as I can tell, it is not possible to get the details of which submit
button was clicked from the submit event of the form, as the event target
will always be the form element. The way to implement this would be to
assign a class to each submit button, then attach a click event to them,
like this example:

http://jsbin.com/inuha/edit



badtant-2 wrote:
 
 
 Hi!
 
 I have a submit-event attached to my form. The form contains a few
 different submit-buttons and I wan't to chech which one of them that
 triggered the submit. Shouldn't be to hard but i can't find out how to
 do it.
 
 Thanks
 
 

-- 
View this message in context: 
http://www.nabble.com/which-submit-button-was-clicked--tp25449810s27240p25450711.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.



[jQuery] Re: which submit button was clicked?

2009-09-15 Thread jlcox

script language=JavaScript type=text/javascript
$(document).ready(function() {
  $(#button1, #button2).click(function(event) {
event.preventDefault();
alert($(this).attr(id) +  was clicked);
  });
});
/script
/head
body
form id=form1
  input type=submit id=button1 value=Submit /
  input type=submit id=button2 value=Submit Again /
/form
/body