By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,829 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

change radio box checked status

P: n/a
Please help me.

I have a radio box set, name is in rname variable, want to change the
checked status to the indexed box, index is in ii variable.

I tried

d = getElementById(rname);
d.value = ii; //this works fine if rname is text, textarea
if (d.type == radio) d[ii].checked = true;

I get for the above line an undefined is null or not an object error
for the d[ii].checked = true; statement.

If I set:
d.checked = true;

i.e. without index it sets the very first box to checked

Question: how to set checked the last (or arbitrary in sequence)
radiobox?
Jul 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
laszlo wrote on 25 Nov 2003:

<snip>
if (d.type == radio) d[ii].checked = true;


<snip>

The 'type' property returns a string. You need to change the if
expression so that the line reads:

if ('radio' == d.type) d[ii].checked = true;
^ ^

Mike

--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #2

P: n/a
Michael Winter <M.******@blueyonder.co.uk.invalid> wrote in message news:<Xn*******************************@193.38.113 .46>...
laszlo wrote on 25 Nov 2003:

<snip>
if (d.type == radio) d[ii].checked = true;


<snip>

The 'type' property returns a string. You need to change the if
expression so that the line reads:

if ('radio' == d.type) d[ii].checked = true;
^ ^

Mike


You are right. It is typing error. Still for the line

if ('radio' == d.type) d[ii].checked = true;

I get an "'undefined' is null or not an object" error, apparently referring to

d[ii].checked = true

statment, even if I set ii=0;

laszlo
Jul 20 '05 #3

P: n/a
laszlo wrote on 26 Nov 2003:

<snip>
You are right. It is typing error. Still for the line

if ('radio' == d.type) d[ii].checked = true;

I get an "'undefined' is null or not an object" error,
apparently referring to

d[ii].checked = true

statment, even if I set ii=0;


You're using getElementById() to obtain an array of elements. That
method will only return one element, so subscripting is invalid. A
radio group uses the name attribute to identify the group. Use
getElementByName() instead. This will return a collection of all
elements using that name.

Mike

--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #4

P: n/a
Michael Winter wrote on 26 Nov 2003:

<snip>
You're using getElementById() to obtain an array of elements. That
method will only return one element, so subscripting is invalid. A
radio group uses the name attribute to identify the group. Use
getElementByName() instead. This will return a collection of all
elements using that name.


Correction: The method is 'getElementsByName()'. I omitted the
plural.

--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #5

P: n/a
Thanks, this works.

Michael Winter <M.******@blueyonder.co.uk.invalid> wrote in message news:<Xn*******************************@193.38.113 .46>...
Michael Winter wrote on 26 Nov 2003:

<snip>
You're using getElementById() to obtain an array of elements. That
method will only return one element, so subscripting is invalid. A
radio group uses the name attribute to identify the group. Use
getElementByName() instead. This will return a collection of all
elements using that name.


Correction: The method is 'getElementsByName()'. I omitted the
plural.

Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.