Results 1 to 3 of 3

Thread: Radio buttons with a submit button

  1. #1
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Radio buttons with a submit button

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

    Code:
    <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?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <!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>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    SenatorUppercut (01-15-2013)

  4. #3
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thank you so much! Geez, still so much to learn!

Similar Threads

  1. Convert submit button to Onchange submit
    By stand247 in forum JavaScript
    Replies: 3
    Last Post: 10-25-2011, 09:01 AM
  2. Replies: 0
    Last Post: 02-17-2011, 02:42 AM
  3. Replies: 0
    Last Post: 10-14-2009, 08:59 AM
  4. Radio buttons
    By bobneedshelp in forum Looking for such a script or service
    Replies: 0
    Last Post: 09-05-2009, 10:03 PM
  5. Replies: 2
    Last Post: 04-15-2008, 07:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •