Changing a checkbox's state programmatically in dashcode

Daniel picture Daniel · Mar 21, 2010 · Viewed 40.5k times · Source

Okay, so I'm trying to change a checkbox's state programmatically in dashcode. I've tried:

var checkbox = document.getElementById("checkbox");

// I have tried all the following methods.
checkbox.checked = false;
checkbox.selected = false;
checkbox.value = false;

Answer

Andy E picture Andy E · Mar 21, 2010

Dashboard Widgets just run on WebKit technologies, so code valid for Safari should also be valid in Dashcode. Either of the following should work:

checkbox.checked = true;
checkbox.setAttribute("checked", "true");

The fact that they are not working indicates there is a problem elsewhere in your code. I would check the line

var checkbox = document.getElementById("checkbox");     

Correctly assigns an element to the checkbox variable. Also, check the id of your "checkbox" element is valid and correct (not a duplicate, doesn't have a typo, etc).