Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Radio Button redirect form help

    I am trying to build a page that has a form on it with three questions, each having two answers via radio button. When the user hits submit, depending on their answers to the three questions, it redirects them to a different page.

    This is all I have so far and am stuck, I dont know much JS.


    <script type="text/javascript">


    function whereTo () {
    if ((Goods==true) && (Direct==true) && (SoleSource==true))
    { window.location = "http://www.somesite/page1"; }

    if ((Goods==true) && (Direct==true) && (NetworkID==true) && (Competed==true))
    { window.location = "http://www.somesite/page2"; }

    if ((Goods==true) && (Indirect==true) && (CostCenter==true) && (SoleSource==true))
    { window.location = "http://www.somesite/page3"; }

    if ((Goods==true) && (Direct==true) && (NetworkID==true) && (SoleSource==true))
    { window.location = "http://www.somesite/page4"; }

    if ((Goods==true) && (Indirect==true) && (CostCenter==true) && (Competed==true))
    { window.location = "http://www.somesite/page5"; }

    if ((Goods==true) && (Direct==true) && (NetworkID==true) && (Competed==true))
    { window.location = "http://www.somesite/page6"; }


    }
    </script>

    The form (it only has the inputs not the questions, i know its not setup properly, just wanted to show the inputs):

    <form>
    <input type="radio" id="Goods" name="good" /> Goods<br /><input type="radio" id="Services" name="Services" /> Services

    <input type="radio" id="Direct" name="good" /> Direct<br /><input type="radio" id="Indirect" name="Indirect" /> Indirect

    <input type="radio" id="CostCenter" name="CostCenter" /> Cost Center<br /><br /><input type="radio" id="NetworkID" name="NetworkID" /> Network ID



    <input type="radio" id="SoleSource" name="order" /> Sole Source<br /><input type="radio" id="Competed" name="order" /> Can Be Competed</td>

    <input alt="Submit" onclick=" return whereTo()" />


    </form>

  • #2
    Regular Coder
    Join Date
    Jul 2003
    Posts
    117
    Thanks
    0
    Thanked 17 Times in 17 Posts
    There are many errors in the code; have some lessons in JavaScript first

    To check the checked state of a radio, the code goes like this:
    Code:
    if(documents.forms['redirform'].goods.checked)
    {
    
    }
    The form need to have a name/id

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,210
    Thanks
    75
    Thanked 4,343 Times in 4,309 Posts
    Also, your naming/logic are out of sync with each other.
    Code:
    if ((Goods==true) && (Direct==true) && (SoleSource==true))
    ...
    <input type="radio" id="Goods" name="good" /> Goods
    <input type="radio" id="Direct" name="good" /> Direct
    As written, only *one* of "Goods" or "Direct" CAN be true! When was is checked, the other will automatically be unchecked.

    Remember, radio buttons are grouped *BY NAME*. The id's and the physical layout of the page have nothing to do with how they are grouped. Only buttons with the same name="..." values are grouped.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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