473,573 Members | 2,932 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

assistence needed getElementById + array for radiobutton

Hello all,

I use the following javascript function in a html document to set the
level of one of eight available radiobuttons. The line that's
commented out works fine under IE, but I need to rewrite it so that
it's W3C compliant. Reading through earlier messages I concluded I
should go with getElementById but this doesn't work. What am I doing
wrong?

Your help is much appreciated.

Sofie

function SetRadioLevel(i Level)
{
document.getEle mentById('radio button')[8-iLevel].checked = true;
// document.all.ra diobutton[8-iLevel].checked = true;
}
which refers to:
<input type="radio" name="radiobutt on"
value="radiobut ton" onClick="JavaSc ript:SetZoomLev el(8)">
<input type="radio" name="radiobutt on"
value="radiobut ton" onClick="JavaSc ript:SetZoomLev el(7)">
<input type="radio" name="radiobutt on"
value="radiobut ton" onClick="JavaSc ript:SetZoomLev el(6)">
<input type="radio" name="radiobutt on"
value="radiobut ton" onClick="JavaSc ript:SetZoomLev el(5)">
<input type="radio" name="radiobutt on"
value="radiobut ton" onClick="JavaSc ript:SetZoomLev el(4)">
<input type="radio" name="radiobutt on"
value="radiobut ton" onClick="JavaSc ript:SetZoomLev el(3)">
<input type="radio" name="radiobutt on"
value="radiobut ton" onClick="JavaSc ript:SetZoomLev el(2)">
<input type="radio" name="radiobutt on"
value="radiobut ton" onClick="JavaSc ript:SetZoomLev el(1)">
Jul 20 '05 #1
3 36168
sofie wrote on 01 Dec 2003:
Hello all,

I use the following javascript function in a html document to
set the level of one of eight available radiobuttons. The line
that's commented out works fine under IE, but I need to rewrite
it so that it's W3C compliant. Reading through earlier messages
I concluded I should go with getElementById but this doesn't
work. What am I doing wrong?
What you have written below shouldn't work in any browser.
document.getEle mentById() is supposed to return a single element. IDs
are unique in a document, so there shouldn't be any possibility of
returning more than one. Also, it should only return the element with
a matching id attribute - name shouldn't even be considered. I just
wanted to point that out...

The fix is /really/ simple: use document.getEle mentsByName(). This is
designed to return a collection of all elements that have a matching
name attribute. However, be aware: the returned elements can appear
anywhere in the document. You can't get elements from a specific
scope. Make sure that the group returned can only be a unique group.
That is, the 'SetZoomLevel' group below should be the only controls
anywhere in your document with the name 'radiobutton'.
function SetRadioLevel(i Level)
{
document.getEle mentById('radio button')[8-iLevel].checked =
true;
// document.all.ra diobutton[8-iLevel].checked = true;
}

<input type="radio" name="radiobutt on" value="radiobut ton"
onClick="JavaSc ript:SetZoomLev el(8)">


A question: why are you using the JavaScript protocol in an intrinsic
event? That's supposed to only be used as a URI specifier. To declare
what language intrinsic events use, you must (that is, it is
*mandatory*) specify the default language using either a META element
or a HTTP header:

<META http-equiv="Content-Script-Type" content="text/javascript">

Without it, your HTML document is invalid, and depends on unreliable
browser behaviour. Browsers don't have to execute intrinsic events if
a default language isn't specified.

Mike

--
Michael Winter
M.******@blueyo nder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #2
> I use the following javascript function in a html document to set the
level of one of eight available radiobuttons. The line that's
commented out works fine under IE, but I need to rewrite it so that
it's W3C compliant. Reading through earlier messages I concluded I
should go with getElementById but this doesn't work. What am I doing
wrong? function SetRadioLevel(i Level)
{
document.getEle mentById('radio button')[8-iLevel].checked = true;
// document.all.ra diobutton[8-iLevel].checked = true;
} which refers to: <input type="radio" name="radiobutt on"
value="radiobut ton" onClick="JavaSc ript:SetZoomLev el(8)">
<input type="radio" name="radiobutt on"
value="radiobut ton" onClick="JavaSc ript:SetZoomLev el(7)">
<input type="radio" name="radiobutt on"
value="radiobut ton" onClick="JavaSc ript:SetZoomLev el(6)">
<input type="radio" name="radiobutt on"
value="radiobut ton" onClick="JavaSc ript:SetZoomLev el(5)">
<input type="radio" name="radiobutt on"
value="radiobut ton" onClick="JavaSc ript:SetZoomLev el(4)">
<input type="radio" name="radiobutt on"
value="radiobut ton" onClick="JavaSc ript:SetZoomLev el(3)">
<input type="radio" name="radiobutt on"
value="radiobut ton" onClick="JavaSc ript:SetZoomLev el(2)">
<input type="radio" name="radiobutt on"
value="radiobut ton" onClick="JavaSc ript:SetZoomLev el(1)">


Give each button a unique id. For example,

<input id="zoom8" type="radio" name="radiobutt on"
value="radiobut ton" onClick="JavaSc ript:SetZoomLev el(8)">

document.getEle mentById('zoom' + iLevel).checked = true;

http://www.crockford.com
Jul 20 '05 #3
Thank you for your reply! I think I can work out that one with these
tips. I hop e you don't mind if I post another one straight away? My
previous question, as well as this one refer to a GIS website whereby a
map is loaded into an iframe.

The main window contains numerous (radio)buttons used for panning,
zooming etc on a map located in an iframe.

This was all working fine under IE, but NS and Mac won't have it. My
initial code was as follows:

The iframe src-document zoomlevel function:

function SetZoomLevel(le vel)
{
iLevel = level;
return Refresh();
}

whereby iLevel is a parameter stored in the <head>.

The main page then refers to this function by:

function SetZoomLevel(le vel)
{
sURL = top.mapframe_ie .SetZoomLevel(l evel);
}

Does this seem like a logical solution, and if so, what do I use to
replace 'top.' to make it W3C compliant?

thanks again,
Sophie

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2836
by: VK | last post by:
Hi! What I'm missing in following code? Cannot get the values of radiobuttons. Starting only one class (GetVariant), it works. When I put two classes together, it doesn't. Regards, VK from Tkinter import * class GetVariant: def __init__(self): self.root = Tk()
6
11177
by: juli | last post by:
Hello, I need a control which will contain radio buttons that will be added in a loop. I am using this control a source of some other control. I tried to use group box windows control and to add the radio buttons this way(in a loop): this.groupBox1.Controls.Add(radio); but I can see there only one radio button . How can I see all of them...
2
1848
by: Spurry Moses | last post by:
Hi, I want to create an array of combo boxes on my form. The only problem is that I don't want to place 3 seperate combo boxes on the form if I can avoid it. I'd just like to create an array and dynamically create them. For example, like the code (that uses Radio Buttons) below. Can I do this and be able to position them on the form as...
9
5500
by: Michael D. Ober | last post by:
In VB 6, you can create control arrays for your option groups and scan with the following code dim opt as OptionButton for each opt in OptionGroup ' Do something next opt I know VB 2005 doesn't have control arrays, so my question is how do I do the equivalent in VB 2005?
7
3975
by: Igor | last post by:
Can I create control array (like TextBox array) in design mode. In vb6 I drow some control at the form and then I copy/paste controls. After that every control have the same name, but they have propetry index which is position of this control in the array. Can I do this in asp.net or I must create control array with code?
5
13146
by: Peted | last post by:
I know you can iterate through a collection of radio buttons in a panel, using a "for each in control" type iteration that c# supports, but is it possible to iterate through the radio buttons collection, as if they were an array of radio buttons ? Basically i want to plonk the radio buttons on a panel then use a for loop to index through...
19
4330
by: vunet.us | last post by:
Hello, My AJAX application paints data into about 500 cells with unique ID every 10 seconds. I am using document.getElementById() to find the right cell. However, I have noticed that document.getElementById() in IE is freezing the browser for about 1 second unlike Firefox. Can anyone suggest any speed improvements for painting data into a...
4
2421
by: dupdupdup | last post by:
Hello there, im needed to develop a gallery for this website. im using hotspots to go to my frames in my flash Each hotspot goes to each frame. The flash is loaded properly. When i right click and click play it goes to the next frame. But the Hotspots just dont work with IE. For your information: This works with other browsers like firefox,...
0
7699
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8027
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8202
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8066
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5594
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5292
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3733
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3733
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1041
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.