Jquery_quest
Jquery_quest

Reputation: 75

Setting checkbox input when specific value equals variable in jquery

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

Answers (1)

Daniel A. White
Daniel A. White

Reputation: 190945

Try this

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

you were missing the quotes around the value.

Upvotes: 2

Related Questions