单选按钮计算

时间:2015-11-05 12:40:28

标签: javascript jquery radio-button

我有两个档案......

  • 轮询

这里的页面是一个民意调查,供用户检查一些具有不同值的单选按钮,以供将来计算。



< script src = "https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" > < /script>
<script>
function show_object(){
  var error = 0;
  var spans = document.getElementsByTagName("span");
  var poll1 = document.vacation.poll1;
  if(poll1.value ==="")
    {
  $("#errgen").fadeIn(2000);
         error = 1;
    }
  else{
   $("#errgen").fadeOut(2000);
    error = 0;
}
  var poll2 = document.vacation.poll2;
  if(poll2.value ==="")
    {
  $("#errgen1").fadeIn(2000);
        error = 1;
    }
  else{
    $("#errgen1").fadeOut(2000);
    error = 0;
}
  var poll3 = document.vacation.poll3;
  if(poll3.value ==="")
    {
  $("#errgen2").fadeIn(2000);
        error = 1;
    }
  else{
    $("#errgen2").fadeOut(2000);
    error = 0;
}
  
    if(error == 0)
    {
      window.location.href = "/poll-result";
    }
  else{
    return false;
  }
}
</script>
&#13;
#errgen {
  display: none;
  color: #ff0000;
  font-style: italic;
  font-size: 10px;
}
#errgen1,
#errgen2
{
  display: none;
  color: #ff0000;
  font-style: italic;
  font-size: 10px;
}
&#13;
<form id="vacation" name="vacation">
  Question
  <br>
  <input type="radio" name="poll1" value="0" />Answer
  <input type="radio" name="poll1" value="1" />Answer
  <input type="radio" name="poll1" value="2" />Answer
  <input type="radio" name="poll1" value="3" />Answer
  <span id="errgen">Select one of the fields</span>
  <br>
  <br>
  <!-- -------------------------------------------------------------------------- -->
  Question
  <br>
  <input type="radio" name="poll2" value="0" />Answer
  <input type="radio" name="poll2" value="1" />Answer
  <input type="radio" name="poll2" value="2" />Answer
  <input type="radio" name="poll2" value="3" />Answer
  <span id="errgen1" class="error">Select one of the fields</span>
  </br>
  </br>
  <!-- -------------------------------------------------------------------------- -->
  Question
  <br>
  <input type="radio" name="poll3" value="0" />Answer
  <input type="radio" name="poll3" value="1" />Answer
  <input type="radio" name="poll3" value="2" />Answer
  <input type="radio" name="poll3" value="3" />Answer
  <span id="errgen2" class="error">Select one of the fields</span>
  </br>
  </br>
  <!-- -------------------------------------------------------------------------- -->
  <input type="button" value="Submit" onclick="return show_object();" />
</form>
&#13;
&#13;
&#13;

  • 轮询结果

这是结果页面。对于每个结果,都会有不同的消息,但我似乎无法通过计算将“轮询”页面重定向到“结果页面”。

<div class="poll">

            <strong>
            <?php 

                 $sum = $_POST['poll1'] + $_POST['poll2'] + $_POST['poll3'];
                 echo "Your result is ".$sum; ?>.</strong><br><br>
                 <p class="justify">
                 <?php

                 switch (true) {
                    case ($sum <= 4):
                        echo "Message1";
                        break;
                    case ($sum >= 5 && $sum <= 9):
                        echo "Message2";
                        break;

                 }


            ?>
        </p>
</div>

当我按下按钮时,是否可以通过计算和每个结果的消息重定向到Poll-Result文件?

由于

0 个答案:

没有答案