View Full Version : Radio Button redirect form help

07-14-2010, 06:05 PM
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"; }


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

<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()" />


07-14-2010, 08:11 PM
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:



The form need to have a name/id

Old Pedant
07-15-2010, 02:08 AM
Also, your naming/logic are out of sync with each other.

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.