/    Sign up×
Community /Pin to ProfileBookmark

radio referrer function

Ji guys, i’m trying to get the box that has been checked from customer with this script, but it gives me an “undefinite” string, is it because al the radios has the same name?
thx
//
<html>
<head>
<script type=”text/javascript”>
var selected
for (i=0; i<document.tv.station.length; i++){
if (document.tv.station[i].checked==true){
selected=i
}
}

</script>
</head>
<body>
<form name=”tv”>
NBC: <input type=”radio” name=”station”><br>
CBS: <input type=”radio” name=”station”><br>
ABC: <input type=”radio” name=”station”><br>
CNN: <input type=”radio” name=”station”><br>
ESPN:<input type=”radio” name=”station”><br>
<input type=”button” value=”selectedbox?” onClick=”alert(selected)” />
</form>
</body>
</html>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@SoreheadJul 10.2008 — You havent given the radio buttons any values...

NBC: <input type="radio" name="station" value="NBC"><br>


... Sorry missread your post.. thats not your problem :-)
Copy linkTweet thisAlerts:
@FangJul 10.2008 — You have to use a function:&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript"&gt;
function selected() {
for (i=0; i&lt;document.tv.station.length; i++) {
if (document.tv.station[i].checked) {
return i;
}
}
return "No selection made";
}

&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form name="tv"&gt;
NBC: &lt;input type="radio" name="station"&gt;&lt;br&gt;
CBS: &lt;input type="radio" name="station"&gt;&lt;br&gt;
ABC: &lt;input type="radio" name="station"&gt;&lt;br&gt;
CNN: &lt;input type="radio" name="station"&gt;&lt;br&gt;
ESPN:&lt;input type="radio" name="station"&gt;&lt;br&gt;
&lt;input type="button" value="selectedbox?" onclick="alert(selected())"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @pipistrello 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.28,
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,
)...