PDA

View Full Version : Radio buttons with a submit button



SenatorUppercut
01-15-2013, 04:16 PM
HTML newbie here. First Post. I'm playing around with radio buttons and am running into an issue. I would like to have a selection of radio buttons to choose from and then a submit button. Based on which radio button is selected when the submit button is clicked I want a specific website to launch. Here is what I have...



<HTML>
<HEAD>
<TITLE>TEST</TITLE>
<script LANGUAGE="JavaScript">
var myOption = false
function initValue() {
myOption = document.forms[0].site[3].checked
}
function fullName(form) {
for (var i = 0; i < form.site.length; i++) {
if (form.site[i].checked) {
break
}
}
window.open(form.site[i].value,_blank)
}
function setShemp(setting) {
myOption = setting

<B>Where do you need to go?:</B>
<P>
<INPUT TYPE="radio" NAME="site" VALUE="http://yahoo.com" onClick="setShemp(false)">Yahoo
<INPUT TYPE="radio" NAME="site" VALUE="http://google.com" onClick="setShemp(false)">Google
<INPUT TYPE="radio" NAME="site" VALUE="http://amazon.com" onClick="setShemp(false)">Amazon
<INPUT TYPE="radio" NAME="site" VALUE="http://cnn.com" onClick="setShemp(true)">CNN
<P>
<INPUT TYPE="button" NAME="Viewer" VALUE="Submit" onClick="window.open(form.site[i].value,_blank)">
</FORM>
</BODY>
</HTML>



Any idea where I'm going wrong?

jscheuer1
01-15-2013, 05:46 PM
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function whichsite(form){
var sites = form.elements.site, i = sites.length;
while (--i > -1){
if(sites[i].checked){
return sites[i].value;
}
}
}
</script>
</head>
<body>
<form action="#" onsubmit="window.open(whichsite(this), '_blank'); return false;">
<b>Where do you need to go?:</b>
<p>
<label><input type="radio" name="site" value="http://yahoo.com/">Yahoo</label>
<label><input type="radio" name="site" value="http://google.com/">Google</label>
<label><input type="radio" name="site" value="http://amazon.com/">Amazon</label>
<label><input type="radio" name="site" value="http://cnn.com/" checked>CNN</label>
<p>
<input type="submit" value="Submit">
</form>
</body>
</html>

SenatorUppercut
01-15-2013, 05:51 PM
Thank you so much! Geez, still so much to learn!