Closed Bug 45867 Opened 24 years ago Closed 23 years ago

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

Categories

(Core :: XBL, defect, P3)

x86
FreeBSD
defect

Tracking

()

RESOLVED INVALID
mozilla1.0

People

(Reporter: pete, Assigned: bugzilla)

Details

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
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>).
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
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
Closed: 23 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.