You are here: irt.org | FAQ | JavaScript | Form | 8 | Q995 [ previous next ]
Try:
<html>
<head>
<script language="JavaScript"><!--
function go(what) {
for (var i=0; i<3; i++) {
if (what.sameName[i].checked == true)
location.href = what.sameName[i].value;
}
}
//--></script>
</head>
<body>
<form>
<br><input type="radio" name="sameName" value="http://www.irt.org/script/faq.htm"> JavaScript FAQ
<br><input type="radio" name="sameName" value="http://www.irt.org/articles/script.htm"> JavaScript Articles
<br><input type="radio" name="sameName" value="http://www.irt.org/games.htm"> JavaScript Games
<p>
<input type="button" onClick="go(this.form)" value="Go">
</form>
</body>If you need a default location, in case the user does not select one of the radio buttons, then use the following go() function instead:
function go(what) {
var chosen = false;
for (var i=0; i<3; i++) {
if (what.sameName[i].checked == true) {
chosen = true;
location.href = what.sameName[i].value;
}
}
if (!chosen)
location.href = 'defaultLocation.htm';
}