Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Check if button is clicked

Tags:

I have two buttons in a form and want to check which one was clicked. Everything works fine with radioButtons:

if($("input[@name='class']:checked").val() == 'A') 

On simple submit button everything crash.

Thanks!

like image 540
hobok Avatar asked Mar 14 '13 08:03

hobok


People also ask

How do you check if a button has been clicked in jQuery?

Show activity on this post. jQuery(':button'). click(function () { if (this.id == 'button1') { alert('Button 1 was clicked'); } else if (this.id == 'button2') { alert('Button 2 was clicked'); } });

How can stop multiple buttons clicking at the same time in jQuery?

Present Code click(function (e) { // Prevent button from double click var isPageValid = Page_ClientValidate(); if (isPageValid) { if (isOperationInProgress == noIndicator) { isOperationInProgress = yesIndicator; } else { e. preventDefault(); } } }); });

Which method is used to set a click event on a button?

jQuery click() Method The click event occurs when an element is clicked. The click() method triggers the click event, or attaches a function to run when a click event occurs.


1 Answers

$('#submit1, #submit2').click(function () {    if (this.id == 'submit1') {       alert('Submit 1 clicked');    }    else if (this.id == 'submit2') {       alert('Submit 2 clicked');    } }); 
like image 115
Kautil Avatar answered Nov 10 '22 10:11

Kautil