Amanda615
Amanda615

Reputation: 7

Having Problems creating an if else statement to go to multiple pages based on the score of a quiz

I successfully created a tallied list that is scored and now I need to link the score to a specific next page or score page. there are 28 different score pages one fore each possible score. can some one please help me with the if else statements for this when I use what I think should be used it comes up completely wrong and errors out.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Toxic Test Quiz</title>




<link type="text/css" rel="stylesheet" href="https://fast.fonts.net/cssapi/731cabbe-df4e-4566-ac88-f64a4500c6b6.css"/>

<link href='http://fonts.googleapis.com/css?family=Pathway+Gothic+One' rel='stylesheet' type='text/css'>

<link type="text/css" rel="stylesheet" href="https://fonts.googleapis.com/css?family=Josefin+Sans:100,400,700,100italic,400italic,700italic"/>

<link href="styles.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
  function unhide(divID) {
    var item = document.getElementById(divID);
    if (item) {
      item.className=(item.className=='hidden')?'unhidden':'hidden';
    }
  }
</script>

</head>
<body>
<form>
   <table style="width: 880px;">
     <tr>
       <td>
            <input type=checkbox name=b1>Ammonium Hydroxide<br/><br>
        <input type=checkbox name=b3>2-Butoxyethanol<br/><br>
        <input type=checkbox name=b5>Di-(Palm Carboxyethyl)<br/><br>
        <input type=checkbox name=b7>Methoxydiglycol<br/><br>
        <input type=checkbox name=b9>Benzalkonium Chlorides<br/><br>
        <input type=checkbox name=b11>Phosphates<br/><br>
        <input type=checkbox name=b13>Silicon Compounds<br/><br>
            </td>


            <td>
            <input type=checkbox name=a1>Hydrozincite<br/><br>
        <input type=checkbox name=a3>Antifoam<br/><br>
        <input type=checkbox name=a5>Buffer<br/><br>
        <input type=checkbox name=a7>Glycol Ethers<br/><br>
        <input type=checkbox name=a9>Glutaral<br/><br>
        <input type=checkbox name=a11>Ethanolamine<br/><br>
        <input type=checkbox name=a13>Alumina<br/><br>
            </td>

            <td>
            <input type=checkbox name=a2>Polyacrylates<br/><br>
        <input type=checkbox name=a4>Polyethylene Glycol<br/><br>
        <input type=checkbox name=a6>Ethanolamine<br/><br>
        <input type=checkbox name=a8>Atrazine<br/><br>
        <input type=checkbox name=a10>Alcohol Ethoxylates <br/><br>
        <input type=checkbox name=a12>Petroleum<br/><br>
        <input type=checkbox name=a14>Polysorbate-20 <br/><br>
            </td>

            <td>
            <input type=checkbox name=b2>Sodium Tripolyphosphate<br/><br>
        <input type=checkbox name=b4>Myristalkonium Saccharinate<br/><br>
        <input type=checkbox name=b6>Alcohol Alkoxylates<br/><br>
        <input type=checkbox name=b8>Poloxamer 124 <br/><br>
        <input type=checkbox name=b10>Hexoxyethanol<br/><br>
        <input type=checkbox name=b12>Methylisothiazolinone<br/><br>
        <input type=checkbox name=b14>Triethanolamine<br/><br>
                                 </td>
                             </tr>
                           </table>

                           <input type=button onclick="doIt(this.form)" value="SUBMIT">


<BR>YOUR FINAL HOUSEHOLD TOXICITY SCORE: <input size=2 type=text name=clicked value=0 onfocus=blur()>
</form>

<script>
function doIt(_f)
{
    var _countCK=0;
    var _countTL=0;
    //get all the input types...new way
    var cboxarr = _f.getElementsByTagName('input');
    for(var i=0;i<cboxarr.length;i++)
    {
        //declare your _obj variable as the particular elements...rest the same
        var _obj = cboxarr[i];
        if(_obj.name!=undefined)
        {
          if(_obj.type=="checkbox")
          {
            _countTL++;
            if(_obj.checked)
              _countCK++;
          }
        }
    }
    _f.clicked.value=_countCK;
    _f.notclicked.value=0+_countTL-_countCK;
} 
</script>

                           if (_countCK===0){
            <a href="mommysclub.com/toxictest/results-0"><img style="float: right; margin: 0 150px 0 0;" src="images/nextbtnp1.png"></a>      
        }else (_countCK===1){
            <a href="mommysclub.com/toxictest/results-1"><img style="float: right; margin: 0 150px 0 0;" src="images/nextbtnp1.png"></a>      
        }else (_countCK===2){
            <a href="mommysclub.com/toxictest/results-2"><img style="float: right; margin: 0 150px 0 0;" src="images/nextbtnp1.png"></a>      
        }else (_countCK===3){
            <a href="mommysclub.com/toxictest/results-3"><img style="float: right; margin: 0 150px 0 0;" src="images/nextbtnp1.png"></a>      
        }else



</body>
</html>

Upvotes: 0

Views: 73

Answers (2)

user2517028
user2517028

Reputation: 844

I think you can do the following, if your links only differs in "_countCK"

Add to the script section:
(If you're using Jquery)

$("#myLink").prop("href", "mommysclub.com/toxictest/results-" + _countCK);

(If not)

document.getElementById("myLink").href= "mommysclub.com/toxictest/results-" + _countCK;

And for the HTML:

<a id="myLink" href="#"><img style="float: right; margin: 0 150px 0 0;" src="images/nextbtnp1.png"></a> 

Upvotes: 0

Suman Bogati
Suman Bogati

Reputation: 6349

The structure of if else for your need should be like this.

if(_countCK===0){

}else if(_countCK===1){

}else if(_countCK===2){

}

You are doing something like this which is wrong

if (_countCK===0){

}else (_countCK===1){

}else (_countCK===2){

}

Upvotes: 1

Related Questions