Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
157
rated 0 times [  163] [ 6]  / answers: 1 / hits: 20965  / 14 Years ago, tue, september 28, 2010, 12:00:00

I have two buttons: btnAdd and btnUpdate. I have written a jquery function for button btnUpdate to validate some fields in the web page like:



$(function() {

$('#<%=btnUpdate.ClientID %>').click(function() {
code here
});
});


I want to do the same thing when btnAdd is clicked. So I have to write the same function again for btnAdd. Is there other way to avoid this?



(If I write one javascript function and call the same function in the button click event of both buttons, it's fine. But is there any way using jQuery?)


More From » jquery

 Answers
3

Just make a selection of two buttons, separated by a comma: (#add, #update).click...
Looks like this in your code:



$(function() { 

$('#<%=btnUpdate.ClientID %>, #<%=btnAdd.ClientID %>').click(function() {
code here
});
});

[#95483] Friday, September 24, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
destiniemartinac

Total Points: 92
Total Questions: 106
Total Answers: 111

Location: Cyprus
Member since Mon, Oct 24, 2022
2 Years ago
destiniemartinac questions
Thu, Oct 28, 21, 00:00, 3 Years ago
Sat, Mar 13, 21, 00:00, 3 Years ago
Wed, May 20, 20, 00:00, 4 Years ago
;