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!

Looping over list in JQM

Status
Not open for further replies.

twcman

Programmer
Jun 28, 2001
284
US
I am using JQ/JQM. In the code below, I get a list of userid's in the data.userids ajax result returns. That is working correctly because I get an expected list of 7,166 back. These userid's correspond to a checkbox(sendtext_userid or sendtext_7). I am trying to loop through the checkboxes and check the ones that have an id listed in the returned result set.
I just cannot get the it to loop through the array list... any ideas?


if(data.result=='success'){
$('#sendmessagefrm :checkbox').each(function(){
var cbid = $(this).attr("id");
var uids=$(data.userids).toArray();
$.each([uids],(function() {
var userid = 'sendtext_'+ $(this).val();
if(cbid=userid){
$('#'+ userid + 'input:checkbox').attr('checked', true);
}

// and the rest of your code
}));

Chris Scott
 
Don't loop through the checkboxes. Just the data array.

For each item in the array assemble a unique Id for the checkbox and set its checked attribute. Jq will handle the internal looping of the Dom to find the relevant checkbox.

In your code there are a whole bunch of syntax errors so I'm surprised it works at all. But something like this should work

Code:
for (var i=0; i<uuids.length; i++){
 $('#'+uuids[i]).attr('checked', 'checked');
}
Assuming that the uuid is the Id of the checkbox in the Dom

You have not posted the code you use to generate the uuids server side and receive them clientside. I suspect this to be a potential error area. Assuming php I would generate a clean numerical array of uuids encode it with json_encode before returning to jquery. Then you can use thr array directly without recasting it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top