M
Michael Repucci
I'm having an unexpected problem... curious if anyone can point out my
mistake, has a work-around solution, or has simply seen this before.
I'm using Javascript to add input checkbox elements to an xhtml page,
and would like to be able to query the state of these elements on
click. In IE7 this works fine but in Firefox 2 the current state isn't
reported correctly by either the checked or defaultChecked attributes.
I include below the text for an test.html and test.js which
demonstrate the problem I'm having in a simplified version.
----- test.html -----
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="test.js"></script>
</head>
<body>
<p>Please click my box!</p>
<p id="parody"></p>
<p>I've put my box in a box for you....</p>
</body>
</html>
----- test.js -----
window.onload = function() {
makeMybox();
}
function clickMybox(mybox) {
var checked = mybox.getAttribute("checked");
var defaultChecked = mybox.getAttribute("defaultChecked");
var value = mybox.getAttribute("value");
alert("value=" + value + "\n" + "checked=" + checked + "\n" +
"defaultChecked=" + defaultChecked);
listItems.style.display = (listItems.style.display=="list-
item") ? "none" : "list-item";
}
function makeMybox() {
var mybox = document.createElement("input");
mybox.setAttribute("type","checkbox");
mybox.setAttribute("name","myform");
mybox.setAttribute("value","mybox");
mybox.onclick = function() {
clickMybox(this);
}
var parody = document.getElementById("parody");
parody.style.margin = "20px";
parody.style.width = "20px";
parody.style.border = "solid black 5px";
parody.appendChild(mybox);
}
mistake, has a work-around solution, or has simply seen this before.
I'm using Javascript to add input checkbox elements to an xhtml page,
and would like to be able to query the state of these elements on
click. In IE7 this works fine but in Firefox 2 the current state isn't
reported correctly by either the checked or defaultChecked attributes.
I include below the text for an test.html and test.js which
demonstrate the problem I'm having in a simplified version.
----- test.html -----
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="test.js"></script>
</head>
<body>
<p>Please click my box!</p>
<p id="parody"></p>
<p>I've put my box in a box for you....</p>
</body>
</html>
----- test.js -----
window.onload = function() {
makeMybox();
}
function clickMybox(mybox) {
var checked = mybox.getAttribute("checked");
var defaultChecked = mybox.getAttribute("defaultChecked");
var value = mybox.getAttribute("value");
alert("value=" + value + "\n" + "checked=" + checked + "\n" +
"defaultChecked=" + defaultChecked);
listItems.style.display = (listItems.style.display=="list-
item") ? "none" : "list-item";
}
function makeMybox() {
var mybox = document.createElement("input");
mybox.setAttribute("type","checkbox");
mybox.setAttribute("name","myform");
mybox.setAttribute("value","mybox");
mybox.onclick = function() {
clickMybox(this);
}
var parody = document.getElementById("parody");
parody.style.margin = "20px";
parody.style.width = "20px";
parody.style.border = "solid black 5px";
parody.appendChild(mybox);
}