Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

input:checked not working

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
US
I am trying to collect all the pkey attributes from a checkbox.

If I do:

Code:
$('.chexPass input:checked').each(function () {
   $("#ChecklistSelected").val($("#ChecklistSelected").val() + $(this).attr("pkey").val() + ",");
 });

It doesn't find anything.

If I do $('.chexPass'), it works fine and finds all the checkboxes and the ones that checked will have a value of "true".

I would like to use the .each loop but if it doesn't work, I can check each value.

Anyone know why it doesn't work?

Thanks,

Tom
 
how about
Code:
$('.chexPass:checked').each(function () {
   $("#ChecklistSelected").val($("#ChecklistSelected").val() + $(this).attr("pkey").val() + ",");
 });

assuming the input's have the class applied to them, hard to tell with no markup to view!

Also you seem to be using custom attributes, there is a new attribute in the standards for this, it is called 'data'

so you should use
Code:
$(this).data('pkey')

and the HTML would be
Code:
<input type="checkbox" data-pkey="my value" value="???" />



"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top