/    Sign up×
Community /Pin to ProfileBookmark

Problem with radio buttons

I’m having trouble using radiobuttons in a javascript program I’m putting together.

<form name=”form1″ method=”post” action=””>>
<input type=”radio” name=”radiobutton” value=”ten”>
<input type=”radio” name=”radiobutton” value=”eleven”>
</form>

I try to find out what radiobutton is selected from a function between the <head> tags.

I’m trying to find the value like this:

variable = self.form1.radiobutton.value

OR

if (self.form1.radiobutton.ten.checked == true)

and other variations but I haven’t been able to find which radiobutton has been selected. Please help. Thanks.

Stephen

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@hungrydinoauthorSep 01.2003 — ignore the second ">", it was a typo in the post, not the script. Thanks.

Stephen
Copy linkTweet thisAlerts:
@XinSep 01.2003 — you might want to use:

if (document.form1.radiobutton[0].checked) { ... }

or form a loop to test the document.form1.radiobutton array.
Copy linkTweet thisAlerts:
@lilluSep 01.2003 — Hi all,

Just for clarity here's a very simple function that loops through the radioGroup (the name I gave the radio buttons). form1 is the name of the form in which the radio buttons live.

function checkRadio()

{

for (i=0; i<document.form1.radioGroup.length; i++)

{

if (document.form1.radioGroup[i].checked == true)

{ // code to do something with the checked button }

}

}
×

Success!

Help @hungrydino 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.3,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...