/    Sign up×
Community /Pin to ProfileBookmark

Help with getting radio button object array in javascript

I’ve been struggling with this for 2 days – I figure either I’m way out in left field or I’m missing something obvious. Please help!

I have an HTML form, and I’m using javascript to validate that a radio button has been selected. From the documentation I’ve read on WC3 and MSDN this code should work, but it doesn’t. What am I doing wrong?

HTML Snippet:

<DIV id=”oRadio”>
<p>Do you like radio buttons?&nbsp;
Yes <input type=”radio” name=”Radio Buttons” value=”Yes”>&nbsp;
Maybe <input type=”radio” name=”Radio Buttons” value=”Maybe” >&nbsp;
No <input type=”radio” name=”Radio Buttons” value=”No” ></p>
</div>

JavaScript Snippet:
var radioList = document.body.getElementsByTagName(“oRadio”);

Thanks in advance for your help!
Sherri

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@JPnycNov 10.2005 — document.body.getElementsByTagName("oRadio"); There is no "oRadio" tag. If you use that method, it can only return a collection of existing HTML tags on the page. Also, inputs are required to be inside a form, yet I don't see any form tags. You reference them like [url=http://www.javascriptkit.com/jsref/radio.shtml]this[/url]
Copy linkTweet thisAlerts:
@S-ScottauthorNov 10.2005 — The radio buttons are in a form - I just didnt include the entire source code.

I need a way to get access to the radio buttons without using the "name" field. For other reasons I don't want to go into here, the "name" field contains a blank, so I can't use the "name" field.

The MSDN page gave an example where "div" was used to create a group ("oRadio"), and then they used getElementsByTagName to get access to that group, but I can't get it to work.

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/getelementsbytagname.asp

thanks,

Sherri
×

Success!

Help @S-Scott spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...