Log in

View Full Version : auto submit form on page refresh



mutago
04-25-2014, 10:38 PM
Hi everyone, i need to auto submit a form on page refresh every 5 seconds.
This is what i have done but does not work



<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
<form id="myform" name="myform" action="POSTadat.php" method="POST">
<input type="text" name="myname">
<input type="submit">
</form>

<script>
$(document).ready(function() {
setTimeout(function() {
$('#myform').submit();
}, 1000);
$('#myform').submit(function(e) {
e.preventDefault();

});
});
</script>
</body>
</html>

jscheuer1
04-30-2014, 07:20 AM
This prevents the form from submitting:



$('#myform').submit(function(e) {
e.preventDefault();

});

It's kind of unclear what you really want to have happen. I think what you want is for the form to submit to the server without the page changing, and that you want this to happen every 5 seconds. If so, the form could be submitted via ajax as part of a setInterval loop of 5 seconds.

But your post is so unclear to me that I hesitate to write out any code for it. Please state precisely what you want to have happen, and just as importantly why, so that I might understand what sort of help to give.

mutago
05-01-2014, 02:36 AM
This is what am trying to achieve. Am retrieving values from database into a form inputs
<input type=text name=message value="<?php echo htmlentities($message); ?>">
I want the form to be auto submitting every 5 seconds whenever there is a value in the input form as fetched from database.
If there is no value in the form input and 5 second has reached, let it not auto submit.

Thank You