I have two input checkboxes, and I want to check/uncheck them with jQuery:
<input type="checkbox" name="user1" value="1" id="u1" onclick="loadUserCalendar(1)">
<input type="checkbox" name="user2" value="2" id="u2" onclick="loadUserCalendar(2)">
JavaScript code:
var list = new cookieList("calendar_users");
var users = list.items();
for (var i = 0; i < users.length; i++) {
$('input[name="user' + users[i].substr(1,1) + '"]').attr('checked', true);
console.log('substring: ' + users[i].substr(1,1));
console.log('enabling user ' + users[i]);
}
var users contains these values: u1,u2 . To only get the user ID, I perform a substring, which gets me the correct number as you can see below in the console output.
Console output:
substring: 1
enabling user u1
substring: 2
enabling user u2
I have no idea, why the checkboxes are not checked when the code ran. What am I doing wrong here?
Edit: I am using jQuery 1.4.4 due to compatibility reasons, that's why I am using .attr()