I have several radio buttons with the same name. Like this:
You could add just a single listener that listens to all radio buttons, rather than individual listeners.
using jquery, you could do it like this
$(document).ready(function(){
$('input[type=radio]').click(function(){
alert(this.value);
});
});
Demo
For only the radios within a form with id formA
$(document).ready(function(){
$('#formA input[type=radio]').click(function(){
alert(this.value);
});
});
For only radios with an id myradio
$(document).ready(function(){
$('input[type=radio]').click(function(){
if (this.id == "myradio")
alert(this.value);
});
});
Demo