Closed
Bug 137699
Opened 23 years ago
Closed 23 years ago
Radio buttons are not checked when property set from Javascript
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
VERIFIED
INVALID
People
(Reporter: marcus, Assigned: jst)
References
()
Details
I am working on a site where I need to have the radio buttons have a default
value that is based on a database value (varied). I tried to set the default
value from javascript, but the "checked" value for the radio button does not
maintain state when the body has completed loading.
In order to replicate this, I made the test.html page located at
http://breese.ws/~marcus/test.html
It first creates a form with three radio buttons. And a "Test" button that
displays the currently selected button (javascript test_radio() function).
I then set the default radio button to 1 (the second button).
I then run the test_radio function, and it properly says that the second button
is checked.
I then run the test_radio() as the OnLoad Event, and it inappropriately says
that there is no checked button.
I tested the page using IE 5, and it works as expected.
I verified this bug on Windows build 2002021104 and Linux build 20020326
I'm not sure if this is a radio button specific bug, or a radio button /
checkbox bug, or if it is a symptom of something larger. I don't know the
source code well enough to debug it myself.
I hope that this helps...
test.html
================================================================
<html><head><title>Mozilla radio button bug test page</title></head>
<body onload="test_radio()">
<form name="myform">
<input type="radio" name="myradio" value="1"> First button<br>
<input type="radio" name="myradio" value="2"> Second button<br>
<input type="radio" name="myradio" value="3"> Third button<br>
<input type="button" value="Test" onclick="test_radio();">
</form>
<script>
<!--
// default to button #2 being checked
document.myform.myradio[1].checked=1;
test_radio();
function test_radio() {
checked=false;
for (i=0; i<document.myform.myradio.length; i++) {
if (document.myform.myradio[i].checked==true) { checked=true; alert
('Button #'+(i+1)+' is checked'); }
}
if (checked==false) { alert ("No button is checked"); }
}
//-->
</script>
</body></html>
Reporter | ||
Comment 1•23 years ago
|
||
I do have a work around, and it is to initialize the radio buttons using a
setTimeout function where the timeout is low (100ms). However, this is far from
optimal, or expected behavior.
Comment 2•23 years ago
|
||
Markus, what build are you using? Using linux/PC build 2002-04-12-21 I do not
see this bug....
Reporter | ||
Comment 3•23 years ago
|
||
I just downloaded a nightly build, and lo and behold, it works. Ug. I'm sorry
for the extra email.
I was running the stock 0.9.9 build 2002021104 windows and Linux/2002032xxxxx
somthing.
I appologize for the error. Thanks for the help.
Status: UNCONFIRMED → RESOLVED
Closed: 23 years ago
Resolution: --- → INVALID
Component: DOM: HTML → DOM: Core & HTML
QA Contact: stummala → general
You need to log in
before you can comment on or make changes to this bug.
Description
•