473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

change radio box checked status

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
5 12873
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fire Juggler | last post by:
I have a database which holds data to say On or Off, i have a form with a radio group called status. I can change the status and submit it to the database fine. But how do u get the radio group to...
15
by: tabonni | last post by:
I want to check each button groups and save the checked value into a 2 dimensional array. But, it doesn't work. Could anyone tell me what's wrong with my code. My code is as follow: <html>...
3
by: Alpha | last post by:
I have 3 radio buttons for include, exclued or 'select all' from the listbox items. If a user selects the 'Select All' button' then all items in listbox is hi-lited as selected. Now, when user...
6
by: Dominic Godin | last post by:
Hi, I have a some radio buttons on a aspx page that cause a post back. I need to get the checked status in the page_init event handler. However it seems that the checked status is only updated...
1
by: Scott D Johnson | last post by:
I am using Visual Studio .NET 2003 (I also have VS .NET 2005 installed) I have a group of four radio buttons, and button, to set the first radio button as checked. When I run the app, and say...
3
by: jahphill | last post by:
Hey. I thought id make a seperate discusion because the other became a bit lengthy and confusing. Aim: Create a php file which works with the script below, which makes the radiobuttons work =D...
2
by: waleed | last post by:
I'm not really good with javascript, basically what I'm trying to do is that I want to be able to handle when the status of a checkbox is changed (i.e. checked or unchecked), I see everybody is...
3
by: kiranbabu | last post by:
<html> <head> <h2 align=center>Blank Tapes Status Form</h2> <br><title>Blank tapes status</title> </head> <body> <br><br> <form name=tapes_status method=post>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.