I have three radio buttons and when I click on one radio button I want to have some functionality using jQuery.
+5
A:
This would fire the code when you click on (for example) the second radio. Is that what you meant?
Example: http://jsfiddle.net/z2f5j/
HTML
<input type='radio' name='somename' />one
<input type='radio' name='somename' />two
<input type='radio' name='somename' />three
jQuery
// :eq() uses a 0 based index, so 1 is the 2nd radio
$(':radio[name=somename]:eq(1)').click(function() {
alert('i was clicked');
});
You could also use a change
event, instead of click
.
Example: http://jsfiddle.net/z2f5j/2/
// run code when the radio is selected
$(':radio[name=somename]:eq(1)').change(function() {
alert('i was changed');
});
patrick dw
2010-09-14 11:11:40