/    Sign up×
Community /Pin to ProfileBookmark

Reverse radio buttons

I am trying to cycle the radio buttons from right to left and back again, but I stop on John when it should return back to Ringo.

[CODE]<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>

<html>
<head>
<title>Extracting Highlighted radio Buttons</title>
<script language=”Javascript”>
function getselectedbutton(buttongroup){
//— This function creates the first button –>
for (var i=0; i<buttongroup.length;i++){
if (buttongroup[i].checked){
return i
}
}
return 0
}
function fullname(form){
//— This function allows the user to view the full name of the selected stooge –>
var i=getselectedbutton(form.stooges)
alert(“You chose “+ form.stooges[i].value +”.”)
}
function cycle(form){
//— This function allows you to cycle through the names –>
var i=getselectedbutton(form.stooges)
if (i–==form.stooges.length){
form.stooges[0].checked=true
} else {
form.stooges[i–].checked=true
}
}
</script>
</head>

<body>
<form>
<p> <b>Select your favorite Beatle:</b></P>
<input type=”radio” Name=”stooges” Value=”John Lennon” Checked>John
<input type=”radio” Name=”stooges” Value=”Paul McCartney” Checked>Paul
<input type=”radio” Name=”stooges” Value=”George Harrison ” Checked>George
<input type=”radio” Name=”stooges” Value=”Ringo Starr” Checked>Ringo
<p> <input type=”button” Name=”Viewer” Value=”View full name…” onClick=”fullname(this.form)”></P>
<input type=”button” Name=”Cycler” Value=”Cycle buttons.” onClick=”cycle(this.form)”>
</form>

</body>
</html>
[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@FangMar 12.2007 —  function cycle(form){
[COLOR="SeaGreen"]//[/COLOR] This function allows you to cycle through the names
var i=getselectedbutton(form.stooges)
if ([COLOR="SeaGreen"]i--==0[/COLOR]){
form.stooges[form.stooges.length-1].checked=true
} else {
form.stooges[i--].checked=true
}
}
×

Success!

Help @pacificwar 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.25,
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,
)...