1

I used the Javascript below. If the time is finished it must redirect to the next page "result.php" by submitting a form. But unfortunately the page displayed is empty. below my form which must send to the next page "result.php". I want to have how to send this form and redirect to the next page. how to send the form with this Javascript to make my page work?

var hoursleft = 3;
var minutesleft = 0;
var secondsleft = 0;

var end1;
var progressBar = document.getElementById('progressBar');
if (localStorage.getItem("end1")) {
  end1 = new Date(localStorage.getItem("end1"));
} else {
  end1 = new Date();
  end1.setMinutes(end1.getMinutes() + minutesleft);
  end1.setSeconds(end1.getSeconds() + secondsleft);
  end1.setHours(end1.getHours() + hoursleft);
}
progressBar.max = end1 - new Date();

var counter = function() {
  var now = new Date();
  var diff = end1 - now;
  diff = new Date(diff);
  var sec = parseInt((diff / 1000) % 60)
  var mins = parseInt((diff / (1000 * 60)) % 60)
  var hours = parseInt((diff / (1000 * 60 * 60)) % 24);
  if (hours < 10) {
    hours = "0" + hours;
  }
  if (mins < 10) {
    mins = "0" + mins;
  }
  if (sec < 10) {
    sec = "0" + sec;
  }
  if (now >= end1) {
    clearTimeout(interval);
    localStorage.setItem("end", null);
    localStorage.removeItem("end1");
    localStorage.clear();

    if (confirm("TIME UP!"))
      window.location.href = "result.php";
    //alert("Time finished!");

  } else {
    progressBar.value = progressBar.max - (end1 - now);
    localStorage.setItem("end1", end1);
    document.getElementById('hours').innerHTML = "<b>" + hours + "</b>&nbsp;&nbsp;&nbsp;" + ":";
    document.getElementById('mins').innerHTML = "<b>" + mins + "</b>&nbsp;&nbsp;&nbsp;" + ":";
    document.getElementById('sec').innerHTML = "<b>" + sec + "</b>";
  }
}
var interval = setInterval(counter, 1000);
 <form class="form-horizontal" role="form" id='question' name="question" method="post"  action="result.php">
 
     <?php
              $number_question=1;
     $limit=10;
     $row = mysqli_query( $conn, "select id,question_name,image from testquestion where email = '".$email."' ");
     $total = mysqli_num_rows( $row );
     $remainder = $total/$number_question;
     $i = 0;
     $j = 1; $k = 1;
     ?>
     <?php while ( $result = mysqli_fetch_assoc($row) ) {
      if ( $i != 0)
        echo "<div  id='question_splitter_$j'>";
      if ( $i == 0)
       echo "<div class='cont' id='question_splitter_$j'>";?>
      <div id='question<?php echo $k;?>' >
      <p class='questions' id="qname<?php echo $j;?>"> <?php echo $k?>.<?php echo $result['question_name'];?>   
      <input type="checkbox" id="review"  name="review" />
       <label style="color:#0080ff">Review</label></p>
      
      </br>
       <?php echo '<img src="data:image/png;base64,'.($result['image']).'" />'; ?></br><br/><br/>
       <input type="text" id="answer<?php echo $result['id'];?>"  name="<?php echo $result['id'];?>" placeholder="Enter your answer"  />
      <br/>
     <br/>
      </div>
      <?php
       $i++; 
        if ( ( $remainder < 1 ) || ( $i == $number_question && $remainder == 1 ) ) {
         echo "<button id='".$j."' class='next btn btn-primary' type='submit'>Finish</button>";
         echo "</div>";
        }  elseif ( $total > $number_question  ) {
         if ( $j == 1 && $i == $number_question ) {
         echo "<button id='".$j."' class='next btn btn-primary' type='button'>Next</button>";
         echo "</div>";
         $i = 0;
         $j++;           
        } elseif ( $k == $total ) { 
         echo " <button id='".$j."' class='previous btn btn-primary' type='button'>Previous</button>
            <a href='review.php'><button id='review.php' class='previous btn btn-primary' type='button'>Review</button></a>
            <button id='".$j."' class='next btn btn-primary' type='submit'>Finish</button>";
         echo "</div>";
         $i = 0;
         $j++;
        } elseif ( $j > 1 && $i == $number_question ) {
         echo "<button id='".$j."' class='previous btn btn-primary' type='button'>Previous</button>
                           <button id='".$j."' class='next btn btn-primary' type='button' >Next</button>";
         echo "</div>";
         $i = 0;
         $j++;
        }
        }
         $k++;
          }

       ?>
        <br/>
       <br/>
     <br/>
    </form>
sonia
  • 49
  • 4

1 Answers1

1

You have to use document.getElementById('question').submit(); with window.location.href = "result.php"; the POST data isnt posted

Rick Grendel
  • 303
  • 1
  • 4
  • 14