0

Input

<input type='checkbox' id='checkbox_to_update' name='checkbox_to_update' value='1'>

Want to pass value to jquery variable

Checkbox is checked

Tried var checkbox_to_update = $("input[name='checkbox_to_update']");

With alert get [object Object]

Then tried var checkbox_to_update = $("#id").attr("checkbox_to_update");

With alert get undefined

What is correct code for `var checkbox_to_update ='

4 Answers 4

4
var checkbox_to_update = $("#checkbox_to_update").val();

Better is here to use ID as selector.

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

Comments

2

Try

$("input[id='checkbox_to_update']").is(':checked');

if Checkbox checked then it returns true else false

Comments

1

Like this using id:

var checkbox_to_update = $("#checkbox_to_update").val();

or using name :

var checkbox_to_update = $("input[name='checkbox_to_update']").val();

Comments

0

Try this, this will help you

JS

var checkbox_to_update =$("#checkbox_to_update").prop('checked');
alert(checkbox_to_update);

Fiddle Here

1 Comment

Try new fiddle it is change from old

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.