i'm not sure if what i'm trying to do is possible or not, but here it is:
i'm creating a dynamic list of checkboxes, basically to allow access to client information on a user by user basis. i use ajax to bring back a full list of clients, then loop through the list and create a checkbox for each client to basically create a checkboxlist. what i want: on each checkbox click to update the database with either added or removed client access. the problem is that the client can't seem to tell which checkbox was clicked.
here's my code:
Expand|Select|Wrap|Line Numbers
- ...
- var sites = search.GetSiteList().value;
- for (var i = 0; i < sites.length; i++)
- {
- // user search site list
- sel.options.length++;
- sel.options[i].value = sites[i].split("-")[0];
- sel.options[i].text = sites[i].split("-")[1];
- if (i > 0) // skip "All"
- {
- // user site assignment list
- var clientId = sites[i].split("-")[0];
- el = document.createElement("input");
- el.type = "checkbox";
- el.id = clientId;
- el.onclick = function(){ChangeUserSiteAccess(clientId)};
- div.appendChild(el);
- div.appendChild(document.createTextNode(sites[i].split("-")[1]));
- div.appendChild(document.createElement("br"));
- }
- }
is there a way to determine which checkbox was clicked? some quick web searching has people normally looping through the entire list to check the .checked property. this is not a great solution for me since a person could have 25 clients selected and 600 unselected.
thanks in advance for any help.