/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Set Radio Button to Checked

I am trying to set a particular radio button’s checked value when the page loads (based on server side information) here’s the code:

[CODE]
<html>
<head>
<script type=”text/javascript”>

var what=”one”;

switch(what)
{
case “one”:
document.send.group1[0].checked = true;
document.send.group1[1].checked = false;
document.send.group1[2].checked = false;
break;

case “two”:
document.send.group1[0].checked = false;
document.send.group1[1].checked = true;
document.send.group1[2].checked = false;
break;

case “three”:
document.send.group1[0].checked = false;
document.send.group1[1].checked = false;
document.send.group1[2].checked = true;
break;

default:
document.send.group1[0].checked = true;
document.send.group1[1].checked = false;
document.send.group1[2].checked = false;
}
</script>
</head>
<body>
<form name=”send” action=”send.php” method=”post”>

<input type=”radio” name=”group1″ value=”1″ />
Radio 1<br />

<input type=”radio” name=”group1″ value=”2″ />
Radio 2 <br />

<input ” type=”radio” name=”group1″ value=”3″ />
Radio 3<br />

<input type=”submit” value=”Submit” /><br />
</form>
</body>
</html>
[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangDec 16.2009 — &lt;script type="text/javascript"&gt;
window.onload=function() {

<i> </i> var what="one";

<i> </i> switch(what)
<i> </i> {
<i> </i>case "one":
<i> </i> document.send.group1[0].checked = true;
<i> </i> document.send.group1[1].checked = false;
<i> </i> document.send.group1[2].checked = false;
<i> </i> break;

<i> </i>case "two":
<i> </i> document.send.group1[0].checked = false;
<i> </i> document.send.group1[1].checked = true;
<i> </i> document.send.group1[2].checked = false;
<i> </i> break;

<i> </i>case "three":
<i> </i> document.send.group1[0].checked = false;
<i> </i> document.send.group1[1].checked = false;
<i> </i> document.send.group1[2].checked = true;
<i> </i> break;

<i> </i> default:
<i> </i> document.send.group1[0].checked = true;
<i> </i> document.send.group1[1].checked = false;
<i> </i> document.send.group1[2].checked = false;
<i> </i> }
};
&lt;/script&gt;
Copy linkTweet thisAlerts:
@over9kauthorDec 16.2009 — OMG of course!

thank you so much Fang!
×

Success!

Help @over9k 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.5,
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,
)...