Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MDMstudios

macrumors member
Original poster
Mar 18, 2008
36
0
Okay, so I got this project, in which I am trying to just set a checkbox to true or false depending on the button they click. My code is essentially this

Code:
var checkbox;

function load()
{
    dashcode.setupParts();
    checkbox = document.getElementById("checkbox");
}

function deselectGroup1(event)
{ // this function is correctly hooked up to the on click event for a button.
    checkbox.checked = false;
}

function selectGroup1(event)
{ // this function is correctly hooked up to the on click event for another button.
    checkbox.checked = true;
}

However, the checkbox doesn't ever change its appearance. I did some tests, and it says the value of checked is undefined before I call one of these functions. I am attaching checkbox to the correct element, and I have tried setting checked in the load function, however nothing works.

I have also tried starting a new project to see if one project was just acting weird, however in the new project nothing changed either.

Any help?
 

Cerebrus' Maw

macrumors 6502
Mar 9, 2008
409
1
Brisbane, Australia
The only reason I ask is that you could be calling the load function before the 'checkbox' element loads into the DOM, meaning that the element id 'checkbox' would not be loaded, and this usually assigns 'undefined' to the variable you try to assign it to in the javascript.

I have never used dashcode, but if not, can you call the function using the body onload call?
Code:
<body onload="load();">

html.....

</body
 

MDMstudios

macrumors member
Original poster
Mar 18, 2008
36
0
The only reason I ask is that you could be calling the load function before the 'checkbox' element loads into the DOM, meaning that the element id 'checkbox' would not be loaded, and this usually assigns 'undefined' to the variable you try to assign it to in the javascript.

I have wondered that, however, I don't believe thats the problem, since even if I assign the variable on a button click it doesn't quite work. I know the load function is being called on the start as well (did some tests).
 

dbourne

macrumors newbie
Jun 3, 2008
7
0
Using the latest Dashcode v3.0.3

Try
checkboxValue.firstElementChild.checked
instead of
checkboxValue.checked
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.