tags:

views:

142

answers:

1

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

+1  A: 

Try this

$('#checkbox[value="'+test_val+'"]').attr('checked', true);

you were missing the quotes around the value.

Daniel A. White
the quotes shouldn't be needed. i'm guessing something else is wrong here.
David Hedlund
thank you very much
Jquery_quest
its working without the quotes now I dunno what was going on
Jquery_quest