I have questions that why my html file cannot connect with php file.
But I am sure that after I click the submit button, value of <input type="hidden" id="t1_response" name="t1_response" value="">
can be given.
However, url doesn't change to php form(like tocsv.php?t1_response=...).
And php gives me an notice:
Notice: Undefined index: t1_response in C:\xampp\htdocs\colors\tocsv.php on line 2
How can I fix it?
<script>
...
function pressSubmit() {
$('#startTrial').hide();
for (var i = 1; i <=3; i++) {
rt = rt + parseFloat(document.getElementById("t"+i+"_rt").value);
};
if (document.getElementById("t1_response").value === "diff") {acc=acc+1};
if (document.getElementById("t2_response").value === "diff") {acc=acc+1};
if (document.getElementById("t3_response").value === "same") {acc=acc+1};
document.write("<div>The average react time: " + rt/3 +" ms</div>");
document.write("<div>Acc Rate:" + acc/3*100+"%</div>");
}
</script>
<style>
...
</style>
<!DOCTYPE html>
<html>
<body>
<h3>Remember the colors</h3>
Press 's' if the two displays are the same. Press 'd' if a color changed (different).<br>
<form action="tocsv.php" method="get">
<input type="hidden" id="t1_response" name="t1_response" value="">
<input type="hidden" id="t1_rt" name="t1_rt" value="">
<input type="submit" id="submitButton" name="submitButton" onclick="javascript:pressSubmit()">
</form>
</body>
</html>
pressSubmit() contains calculating average number and document.write() to display the value to user.
tocsv.php
<?php
echo $_GET["t1_response"];
?>
Error code is clear: you have to define the var t1_response in your php file. I bet you write:
t1_response = $_POST['t1_response ']
but you need:
$t1_response = $_POST['t1_response ']
The html file you post here is ok.
I have solved the problems.
Thanks everyone's help.
Here, in pressSubmit()
, I wrote doucument.write(...)
, which make the page to be overwritten. Thus, it came out to be unable to get the value and I have no idea why so.
Thus, I use alert
to avoid to overwrite the page. And everything works.
Thanks everyone's help again!
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.