0

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 Answer 1

2

Try this

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

you were missing the quotes around the value.

Sign up to request clarification or add additional context in comments.

1 Comment

the quotes shouldn't be needed. i'm guessing something else is wrong here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.