window.location.href不提交表格

时间:2018-11-21 07:56:30

标签: javascript php html

我使用了以下Javascript。 如果时间结束,则必须通过提交表单将其重定向到下一页“ result.php”。但是很遗憾,显示的页面为空。 在我的表格下面,该表格必须发送到下一页“ result.php”。 我想知道如何发送此表单并重定向到下一页。 如何使用此Javascript发送表单以使我的页面正常工作?

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>

1 个答案:

答案 0 :(得分:1)

您必须使用document.getElementById('question').submit();window.location.href = "result.php";使用POST数据未发布

相关问题