I have a table of values and need to get the value of a row's checkbox. What is happening is: If I have a table with 4 rows of data and select the top row, the binding event is being fired for each corresponding row in the table with the same class name. I only want it to fire once and return the value of the row's checkbox that was changed (need both checked and unchecked trigger). Any help is appreciated.
See my fiddle at http://jsfiddle.net/radi8/MgFuu/5/.
I am using the following class (fixed using suggestions by Rob W and Richard D, thanks guys!):
var RequiredField = {
init: function() {
// bind a control structure around the PSN selection table
var psn = $(".psnselect");
//for (var i = 0, ii = psn.length; i < ii; i++) {
// $(psn).change(RequiredField.psnSelect);
//}
psn.change(RequiredField.psnSelect);
},
psnSelect: function(event) {
var evtName = event.currentTarget.name;
var checked = event.currentTarget.checked;
var val = event.currentTarget.value;
alert('PSN Selection: ' + evtName);
}
};
RequiredField.init();