View Full Version : Radio buttons with a submit button

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...

<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) {
function setShemp(setting) {
myOption = setting

<B>Where do you need to go?:</B>
<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
<INPUT TYPE="button" NAME="Viewer" VALUE="Submit" onClick="window.open(form.site[i].value,_blank)">

Any idea where I'm going wrong?

01-15-2013, 05:46 PM
<!DOCTYPE html>
<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){
return sites[i].value;
<form action="#" onsubmit="window.open(whichsite(this), '_blank'); return false;">
<b>Where do you need to go?:</b>
<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>
<input type="submit" value="Submit">

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