Checked property
Grrrr, the simplest things in JS never work for me...This pointless script will make it impossible to check the box. Works fine in Firefox but in Opera and IE, it just operates like a normal checkbox.
<script type="text/javascript">
function runMe()
{
status = document.getElementById("check-box");
status.checked = false
}
</script>
<input type="checkbox" id="check-box" onclick="runMe()"/>
What am I doing wrong?
(I'm not looking to make an impossible to checkbox , I've just broken it down to a simple form to see what my problem is)
pr0gr4mm3r posted this at 03:47 — 22nd December 2007.
He has: 1,502 posts
Joined: Sep 2006
Try this:
<script type="text/javascript">
function runMe()
{
status = document.getElementById("check-box").checked = false;
}
</script>
<input type="checkbox" id="check-box" onclick="runMe()"/>
When you run status = document.getElementById("check-box");, Firefox must assign a pointer or something whereas other browsers do not. In other words, when you assign the checkbox's status to the variable 'status', that variable, 'status' is not related to the checkbox, thus changing the variable does not change the checkbox, unless the variable is a pointer of sorts. That's what I'm guessing Firefox is treating it as.
teammatt3 posted this at 04:48 — 22nd December 2007.
He has: 2,102 posts
Joined: Sep 2003
Thanks pr0gr4mm3r! Works perfectly.
pr0gr4mm3r posted this at 04:53 — 22nd December 2007.
He has: 1,502 posts
Joined: Sep 2006
You're welcome.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.