https://stackoverflow.com/questions/60049329/how-to-5-minute-auto-submit-html-form-and-insert-data-in-mysql-database-using-jvalue into "0" in the database. I am currently using wamp as my local server. Is there a best way how to do this? like using javascript or ajax?
I have a basic html here, where you could just submit the button through an action page, so it inserts the record into the mysql database in phpmyadmin, what I want to know is how to make it auto submit after 5 mins, while setting the blanks fields
this is the html code
<h2><font size="6s">GHS Applicant Assessment Tool</font></h2>
<h5><font size="5s"><p>This exam is an assessment tool to help us place you in the correct account.
</p></font></h5>
<p style="color:red;">* Required</p><br>
<form name="quiz" id="myquiz" onsubmit="return validate()" method="post" action="/ghs/ghsadd.php">
<font size="5">Last name*</font><br>
<input type="text" name="last_name" required><br>
<font size="5">First name*</font><br>
<input type="text" name="first_name" required><br>
<font size="5">Middle Initial</font><br>
<input type="text" name="middle_initial" required><br>
<font size="5"><p class="thick">Highest Educational Attainment*</p></font>
<font size="5"><input type="radio" name="educ_attain" value="hsalsgrad" required> High School
Graduate / ALS Graduate<br>
<input type="radio" name="educ_attain" value="shsgrad" required> Senior High School Graduate<br>
<input type="radio" name="educ_attain" value="undergrad1" required> College Undergraduate 1 year<br>
<input type="radio" name="educ_attain" value="undergrad2" required> College Undergraduate 2 years<br>
<input type="radio" name="educ_attain" value="undergrad3" required> College Undergraduate 3 years<br>
<input type="radio" name="educ_attain" value="undergrad4" required> College Undergraduate 4+
years<br>
<input type="radio" name="educ_attain" value="collegegrad" required> College Graduate<br>
</font><br>
<font size="5"><p class="thick">Logic and Reasoning</p></font>
<p>You will be given 5 minutes to complete this portion.</p><br>
<font size="5"><p>The 4:25 P2P bus takes 1 hour and 45 minutes to arrive in Trinoma. If Joseph takes this bus, what time will he arrive in
Trinoma? *</p>
<input type="radio" name="logic1" value="0" required> 7:05 <br>
<input type="radio" name="logic1" value="0" required> 6:25<br>
<input type="radio" name="logic1" value="1" required> 6:10<br>
<input type="radio" name="logic1" value="0" required> 5:55<br>
<p>Janine’s shoes cost $44.50, her pants cost $20.80 and her t-shirt
cost $14.95. What is the total of her purchases? *</p>
<input type="radio" name="logic2" value="0" required> 85.25<br>
<input type="radio" name="logic2" value="1" required> 80.25<br>
<input type="radio" name="logic2" value="0" required> 82.55<br>
<input type="radio" name="logic2" value="0" required> 80.55<br>
<p>Which number represents the smallest amount? *</p>
<input type="radio" name="logic3" value="0" required> 1/12<br>
<input type="radio" name="logic3" value="0" required> 2/9<br>
<input type="radio" name="logic3" value="0" required> 15/200<br>
<input type="radio" name="logic3" value="1" required> 3/140<br>
</font>
<font size="5"><p class="thick">Grammar</p></font>
<p>You will be given only 3 minutes to complete this portion.</p><br>
<font size="5"><p>I must get _________ - I can't use the internet at all. *<p><br>
<input type="radio" name="grammar1" value="0" required>my computer fix<br> <input type="radio" name="grammar1" value="1" required>my computer fixed<br> <input type="radio" name="grammar1" value="0" required>fixed my computer<br>
<p>Nothing happened at the meeting, ________ it? *<p><br>
<input type="radio" name="grammar2" value="0" required>didn't<br>
<input type="radio" name="grammar2" value="1" required>did<br>
<input type="radio" name="grammar2" value="0" required>does<br>
<p>The boys hurt ________ playing football in the park. *<p><br>
<input type="radio" name="grammar3" value="0" required>theirselves<br> <input type="radio" name="grammar3" value="1" required>themselves<br>
<input type="radio" name="grammar3" value="0" required>themself<br>
<p>_________ was at the party last night. *</p><br>
<input type="radio" name="grammar4" value="0" required>Anyone<br>
<input type="radio" name="grammar4" value="0" required>Anybody<br>
<input type="radio" name="grammar4" value="1" required>everybody<br>
<p>_______ longer do we expect politicians to tell us the truth. *</p><br>
<input type="radio" name="grammar5" value="0" required>Not<br>
<input type="radio" name="grammar5" value="0" required>Any<br>
<input type="radio" name="grammar5" value="1" required>No<br></font>
<font size="5"><p class="thick">Writing</p></font>
<p>You will be assessed in your ability to write in English. Use 3 sentences to answer the<br>
question. Use correct grammar.</p>
<font size="5"><p>Who is your favorite person and why?</p></font>
<textarea rows="4" cols="100" name="ghs_essay" placeholder="Your Answer" required></textarea><br>
<font size="5" class="thick"><p>Reading Comprehension</p></font>
<p>You will be given 7 minutes to complete this portion</p><br>
<font size="5"><p>What time will the festival begin?*</p></font>
<center><img src="readingcomp.jpg" alt="" style="width:700px;height:400px;"><br></center>
<font size="5"><input type="radio" name="reading1" value="0" required>2 PM<br>
<input type="radio" name="reading1" value="1" required>10 PM<br>
<input type="radio" name="reading1" value="0" required>11 AM<br>
<input type="radio" name="reading1" value="0" required>1 PM<br>
</font>
<font size="5"><p>What job will be done the day before the festival begins? *</p></font>
<center><img src="readingcomp.jpg" alt="" style="width:700px;height:400px;"><br></center>
<font size="5"><input type="radio" name="reading2" value="1" required>Setting up the
gym<br>
<input type="radio" name="reading2" value="0" required>Helping the performers<br>
<input type="radio" name="reading2" value="0" required>Cleaning
up the gym<br>
<input type="radio" name="reading2" value="0"
required>Making posters<br></font>
<font size="5"><p>Who is told to talk to Ms. Braxton? *</p></font>
<center><img src="readingcomp.jpg" alt="" style="width:700px;height:400px;"><br></center>
<font size="5"><input type="radio" name="reading3" value="0" required>Performers<br>
<input type="radio" name="reading3" value="1" required>Students<br>
<input type="radio" name="reading3" value="0" required>Teachers<br>
<input type="radio" name="reading3" value="0"
required>Parents<br></font>
<font size="5"><p>In line 3, the word feature is closest in meaning to _______. *</p></font>
<center><img src="readingcomp.jpg" alt="" style="width:700px;height:400px;"><br></center>
<font size="5"><input type="radio" name="reading4" value="0" required>keep<br>
<input type="radio" name="reading4" value="0" required>entertain<br>
<input type="radio" name="reading4" value="1" required>include<br>
<input type="radio" name="reading4" value="0" required>look<br>
</font>
<font size="5"><p class="thick">Listening Comprehension</p></font>
<p>You will be given 3 minutes to complete this portion.</p><br>
<!-- Ryan: "Hey! you can use this line of code for testing embedded videos." <iframe width="500" height="345" src="listeningcompvid.mp4">
</iframe> -->
<video width="500" height="345" controls>
<source src="listeningcompvid.mp4" type="video/mp4">
</video><br><br>
<font size="5"><p> Based on the story, we can conclude that Bill: * </p><br></font>
<font size="5"><input type="radio" name="listening1" value="0" required>has children<br>
<input type="radio" name="listening1" value="1" required>is a student<br> <input type="radio" name="listening1" value="0" required>has a wife<br> <input type="radio" name="listening1" value="0" required>works in an office<br></font>
<font size="5"><p> Based on the story, we can conclude that Bill: * </p><br></font>
<font size="5"><input type="radio" name="listening2" value="1" required>is the eldest
child<br>
<input type="radio" name="listening2" value="0" required>has more than one dog<br>
<input type="radio" name="listening2" value="0" required>is a girl<br> <input type="radio" name="listening2" value="0" required>is an only child<br></font>
<input name="submit" name="submitbutton" type="submit" value="Submit"></input>
</form>
</div>
</body>
</html>
Ajax code to prevent the form from refreshing
<script>
$(function() {
function ajaxSubmit(form) {
$.ajax({
type: form.attr('method'), // <-- get method of form
url: form.attr('action'), // <-- get action of form
data: form.serialize(), // <-- serialize all fields into a string that is ready to be posted
to your PHP file
beforeSend: function(){
},
success: function(data){
}
});
}
$("#locForm").submit(function(e) {
e.preventDefault();
ajaxSubmit($(this));
});
setInterval(function() {
ajaxSubmit($("#locForm"));
}, 10000);
});
</script>
code for autosubmitting every * seconds.
<script>
window.onload = function() {
var auto = setTimeout(function(){ autoRefresh(); }, 100);
function submitform(){
alert('test');
document.forms["myForm"].submit();
}
function autoRefresh(){
clearTimeout(auto);
auto = setTimeout(function(){ submitform(); autoRefresh(); }, 10000);
}
}
</script>
Is their something that I missed why it was not working? I want to set the auto submit after 10 minutes, and automatically submit to the action-page, but also insert the record into database.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 393 |
Nodes: | 16 (2 / 14) |
Uptime: | 35:22:29 |
Calls: | 8,256 |
Files: | 13,132 |
Messages: | 5,877,350 |