June 14, 2010
Several buttons on one form calling same function
Question by user198003
trying to develop web form using jquery.
all i need is to have several (don’t know how many) buttons on one form.
all of those buttons have to call one same function, and to pass one parameter to that function. that function have to do some post method, but i can handle it.
so, my main problem is that i don’t know how to develop JS that will call specific jquery function.
can you help me with this?
Answer by Starx
Or, you can give a common class to all the links and do something like this
A sample HTML
<a class="yourclass" param1="value1" href=#">Text</a>
Now the script
$(".yourclass").click(function() {
var param = $(this).attr('param1');
//now do the remaing
});