Reputation: 75
I am trying to use JQuery to set a checkbox to checked if the input value of the checkbox is equal to some other variable that I have. This is what my code looks like:
var test_val = "test";
$('#checkbox[value='+test_val+']').attr('checked', true);
This does not seem to be working, thanks for the help
Upvotes: 0
Views: 1963
Reputation: 190945
Try this
$('#checkbox[value="'+test_val+'"]').attr('checked', true);
you were missing the quotes around the value.
Upvotes: 2