PDA

View Full Version : Resolved Looping through checkbox array.


dniwebdesign
12-26-2009, 07:22 AM
MERRY CHRISTMAS!!!

Okay...
I have a list of checkboxs all with various data stored via the id, class, and of course value (for when I submit). All checkbox data are created dynamically from MySQL and PHP so the id,class, and value change every time.
<input type="checkbox" value="32" name="invoices[]" id="4681-09122-1261342080" />
<input type="checkbox" value="35" name="invoices[]" id="4680-09121-1261706548" />
<input type="checkbox" value="31" name="invoices[]" id="4681-09121-1261342068" />



$('input[name="invoices[]"]').each(function(i) {
alert($(this).is('.4681'));
});
However this code does not alert whether or or not it is true of false. What am I doing wrong or is even what I'm trying to do possible?

oesxyl
12-26-2009, 01:18 PM
MERRY CHRISTMAS!!!

Okay...
I have a list of checkboxs all with various data stored via the id, class, and of course value (for when I submit). All checkbox data are created dynamically from MySQL and PHP so the id,class, and value change every time.
<input type="checkbox" value="32" name="invoices[]" id="4681-09122-1261342080" />
<input type="checkbox" value="35" name="invoices[]" id="4680-09121-1261706548" />
<input type="checkbox" value="31" name="invoices[]" id="4681-09121-1261342068" />



$('input[name="invoices[]"]').each(function(i) {
alert($(this).is('.4681'));
});
However this code does not alert whether or or not it is true of false. What am I doing wrong or is even what I'm trying to do possible?
- id must start with a char, something like '4681-09121-1261342068' is invalid. Use a literal prefix to fix it when you generate the code. Something like 'm4681-09121-1261342068' for example.
- check for ids to have uniq distinct values in the same page.
- jquery each, take as first argument an object, calback is the second argument.
- I don't have experience with jquery, I could be wrong, but I don't know any 'is'. Can you give me a link or something, where did this come from? Also using a '.' as selector instead of '#' could be a problem. Second problem could be because '4681' is only first part of the id. But this is only a guess.

happy holidays and best regards