Radio Buttons - Need JavaScript to tell which one is cheched please!!

They have: 11 posts

Joined: Sep 1999

Help,
I saw the tutorial on how to see which menu item was selected from a drop down menu, I cant seem to figure the script to do this when trying to determine which radio button a user selects on my form.
I would appreciate any and/or all suggestions. Thanks

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

I don't remember off hand. I'll try to look it up. If anyone knows this before I get back, please post it here. Smiling

They have: 5,633 posts

Joined: Jan 1970

function findSelectedRadio() {
for (i=0; i<document.FORM.RADIO.length; i++) {
if (document.FORM.RADIO[i].checked) {
return i;
}
}
}

alert(findSelectedRadio());

----------
[email protected]
http://go.to/hass

They have: 2,390 posts

Joined: Nov 1998

Lloyd, would you be interested in co-moderating this forum as John is currently very busy.
JP

----------
[red]The Next Step in Website Development [/red] - http://www.what-next.com
The Webmaster Promotion and Resource Center

They have: 11 posts

Joined: Sep 1999

Thank you VERY much lloyd, I have been stuck on that one for two days.
I was using document.forms[0].elements[0].checked

They have: 5,633 posts

Joined: Jan 1970

<zman>
Glad to be a help. Those radio buttons can be a bit misleading at times - I searched for the very same answer but I can assure you it took longer than two days to find the solution.

<JP>
I received an email from John and have sent a reply. I am interested and if you would like to speak to me about it, please email me.

----------
[email protected]
http://go.to/hass

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

It's pretty interesting how our names are so similar. We could really confuse some people if we wanted to. Wink

I'll second the motion for Lloyd as co-moderator. Lloyd has been a big help to me, especially with the JavaScript forms and such. Smiling

They have: 2,390 posts

Joined: Nov 1998

Just to avoid any confusion:
John Stones = JP (I sent you the email from my work address)
John Pllock is the moderator of these forums.
Smiling
JP

----------
[red]The Next Step in Website Development [/red] - http://www.what-next.com
The Webmaster Promotion and Resource Center

They have: 5,633 posts

Joined: Jan 1970

<JP Stones>
I realise that now!

They have: 2,390 posts

Joined: Nov 1998

Smiling
John, euh, JP

----------
[red]The Next Step in Website Development [/red] - http://www.what-next.com
The Webmaster Promotion and Resource Center

They have: 2,390 posts

Joined: Nov 1998

Llyod has agreed to come on board as co moderator, so I hope everyone gives him a good TWF welcome with loads of ridiculously hard questions Smiling
Welcome aboard!
JP

----------
[red]The Next Step in Website Development [/red] - http://www.what-next.com
The Webmaster Promotion and Resource Center

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.