1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Radio Button Links

Discussion in 'JavaScript' started by nimonogi, Nov 1, 2007.

  1. #1
    In the following javascript the radio buttons works when clicked.
    I want to change this and submit a button in order to work.
    ex. The user can change between radio buttons as many times he want and based on the last selection when click the submit button to do the selected action.

    
    <HEAD>
    <SCRIPT LANGUAGE="JavaScript">
    function go(loc) {
    window.location.href = loc;
    }
    </script>
    </HEAD>
    
    <BODY>
    <form name="form">
    <input type="radio" name="loc" onClick="go('http://javascript.internet.com/');"> JavaScript Source<br>
    <input type="radio" name="loc" onClick="go('http://javascript.internet.com/toc.html');"> JSS Table of Contents
    </form>
    
    Code (markup):
    Thanks in advance!
    SEMrush
     
    nimonogi, Nov 1, 2007 IP
    SEMrush
  2. Jamie18

    Jamie18 Peon

    Messages:
    201
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    
    <html>
    <head>
    <title>some page title</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <script type="text/javascript">
    var loc = "";
    
    function go() {
    window.location.href = loc;
    }
    function set_loc(theURL) {
    loc = theURL;
    }
    </script>
    </head>
    
    <body>
    
    <form name="form" action="">
    <div id="content">
    <input type="radio" name="loc" onchange="if(this.checked){set_loc('http://javascript.internet.com/');}">JavaScript Source<br>
    <input type="radio" name="loc" onchange="if(this.checked){set_loc('http://javascript.internet.com/toc.html');}">JSS Table of Contents<br>
    <input type="button" value="Submit" onclick="go();">
    </div>
    </form>
    
    </body>
    </html>
    
    Code (markup):
    this should get the job done for you.. not the cleanest code i've ever made.. and the page is completely useless if javascript is turned off.. you might consider something like this..

    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    
    <html>
    <head>
    <title>some page title</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    </head>
    
    <body>
    <form name="form" action="http://javascript.internet.com/page_chooser.page" method="post">
    <div id="content">
    <input type="radio" name="loc" value="http://javascript.internet.com/">JavaScript Source<br>
    <input type="radio" name="loc" value="http://javascript.internet.com/toc.html">JSS Table of Contents<br>
    <input type="submit">
    </div>
    </form>
    </body>
    </html>
    
    Code (markup):
    with this you would need to create the page_chooser.page, which would be a page written in your server side language, php, coldfusion, etc.. which would basically extract the value of the loc radio button group and than go to that location..
     
    Jamie18, Nov 1, 2007 IP
  3. nimonogi

    nimonogi Active Member

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    80
    #3
    Anyone knows a better way to do this?

    I want the user to be able to change between radio buttons (or click on an image) as many times he want and based on the last selection when click the submit button to follow the appropriate link.

    Thanks.
     
    nimonogi, Nov 4, 2007 IP