Changing checkbox status programmatically in dashcode

Ok, so I am trying to change the state of a checkbox programmatically in dashcode. I tried:

var checkbox = document.getElementById("checkbox"); // I have tried all the following methods. checkbox.checked = false; checkbox.selected = false; checkbox.value = false; 
+7
javascript checkbox dashcode
source share
8 answers

Dashboard widgets run only on WebKit technologies, so the code valid for Safari must also be valid in Dashcode. Any of the following should work:

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

The fact that they do not work indicates a problem elsewhere in your code. I would check the line

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

Correctly assigns an element to a checkbox variable. Also, check that the identifier of your "checkbox" element is valid and correct (no duplicate, no typos, etc.).

+14
source share

This question is one month when I write this answer. This was probably already allowed, but in any case, I would like to add that if you use Dashcode, then the flag is a div that contains one label and one input, and this flag is "real".

If you check the html as it is loaded in Safari, you will notice that "checkbox" is the type of element.

Therefore, the correct way to change the state of the flag would be if we assume that the “input” is its identifier (it could have a default number attached):

 document.getElementById("input").checked="true"; 

or any method you want to use.

The main thing is that you tried to change the state of another div.

Hope this helps!

+6
source share
 checkbox.setAttribute("checked", "checked"); // set checkBox.removeAttribute("checked"); // remove 
+2
source share

I don’t know which browser you used, but when I tested FF 3.6, it works. just put it like this:

 checkbox.checked = false; 

while:

 checkbox = document.getElementById('blablabla'); 

or write like this:

 document.getElementById('idhere').checked = false; 
+1
source share

This question was after about a while. Despite this, the following works for us:

checkbox.childNodes [1] .checked = true; checkBox.childNodes [1] .checked = false;

As pointed out in the previous answer, the way Dashcode creates these controls should go past the div shell that has the actual identifier (a check box in this example) and set the input property, which is a child of node 1.

Finding the actual "identifier" of the input will be problematic since you cannot control which identifier is assigned to the node. For example, if you have two flags, the first will have “enter” as the identifier for the child node 1, and the second will have “input1”, if only from the source that you used “input” or “input1” as the identifier where something in your design already!

There may be another method, but I have not found it yet.

+1
source share

May be:

 checkbox.checked = "checked"; 

Then:

 checkbox.checked = "unchecked"; 
0
source share
 cell = row.insertCell(-1); sel = document.createElement('input'); sel.setAttribute("type", "checkbox") sel.setAttribute("name", "myCheckBox") cell.appendChild(sel); cell.getElementsByTagName('input')[0].checked = true; 

I create a table, a row, then a cell, and create a checkbox in it. I can capture the first input object and set the checked state to true.

0
source share
 var checkbox = document.getElementById("checkbox"); 

there is a problem with this line, it should be

 var checkbox = document.getElementById('#checkbox"); 
-2
source share

All Articles