Hammad Nasir
Hammad Nasir

Reputation: 145

jquery not setting the value of checkbox

whether or not my variable "showforfamilymember" has a value of true or false it always the show checkbox as checked

        <label for="showforfamilymemberchk">Show This Group While Adding Family Member</label>
        <input type="checkbox" name="showforfamilymemberchk" id="showforfamilymemberchk" />

jQuery

var txtshowforfamilymember = $("#showforfamilymemberchk");
txtshowforfamilymember.attr("checked", showforfamilymember);

Upvotes: 0

Views: 25

Answers (2)

Daniel Rosano
Daniel Rosano

Reputation: 695

How are you setting showforfamilymember ?

If you do it like this it should work

var showforfamilymember = false;

if you have the value stored let's say in some string "myValue"

var showforfamilymember = (myValue.toLowerCase() === 'true');

Hope it works

Upvotes: 1

Ramanathan Muthuraman
Ramanathan Muthuraman

Reputation: 752

Try using .prop() instead of .attr()

txtshowforfamilymember.prop("checked", showforfamilymember);

Upvotes: 1

Related Questions