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

});

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!