If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

setting a radio from js doesn't uncheck the previous checked radio

RESOLVED INVALID

Status

()

Core
XBL
P3
normal
RESOLVED INVALID
17 years ago
14 years ago

People

(Reporter: Pete Collins (MDG), Assigned: Blake Ross)

Tracking

Trunk
mozilla1.0
x86
FreeBSD
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

17 years ago
Hey Ben, maybe i'm doing something wrong here . . .

If is set a radio like so:

document.getElementById('aRadio').checked=true;

the previously checked radio remains checked and i have two checked
radios . . .

So i ended up doing this for it to work:

var child=document.getElementById('radioGroupId').childNodes;
for(n=0;n<child.length;n++)
child[n].removeAttribute('checked');
document.getElementById('targetRadio').checked=true;


Thanks

pete

Comment 1

17 years ago
By the way, you can use the .selectedItem setter of <radiogroup> to get
the result you want (i.e., it will remove checked status from the 
current selectedItem, and set it on the new selectedItem (automagic mutual 
exclusion)):

  var radiogroup = document.getElementById("aGroup");
  radiogroup.selectedItem = document.getElementById("aRadio");

(But this bug is really about a possible change to the binding that might make 
individual <radio> elements "aware" of their containment in the <radiogroup>).
(Reporter)

Comment 2

17 years ago
Exactly John, thanks.

I am just use to html behavior.
You set a child to checked and their siblings are aware of the change.

pete
I'm not setting the selectedItem internally. this is wrong.

accepting. 
Status: NEW → ASSIGNED
Target Milestone: --- → M20
Target Milestone: --- → mozilla1.0
hi blake
Assignee: ben → blakeross
Status: ASSIGNED → NEW
(Assignee)

Comment 5

16 years ago
You can't set .checked (which is now .selected) anymore. The only proper way to 
do it is to set the radiogroup's selectedItem. Marking invalid.
Status: NEW → RESOLVED
Last Resolved: 16 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.