Reputation: 77
A php page (let's call it page_one) checks certain values on DB and echoes different questions on screen depending on those values. The user sets some radios and click submit. The code send the radio values to another php file (let's call it page_two) where they are written in the DB and then the code puts new values in hidden fields of a hidden form and submits them loading again page_one, where new questions are presented. And so on till the number of questions-set is finished.
To auto-submit to page_one I use the following javascript inside the php file page_two.
<script>
var auto_refresh = setInterval(function() { submitform(); }, 50);
function submitform()
{
/*alert('test');*/
document.getElementById("hidden-form").submit();
}
</script>
On Firefox (Mac) and Safari (Mac) and iOS(Safari) everything goes right: page_two writes the values in the db and calls back page_one.
Instead of doing the same, Chrome enters in a loop, and continues to call page_two every 50 ms, for thousands of times till something breaks all that.
Any help?
Upvotes: 1
Views: 270
Reputation: 4315
Thats what setInterval
is made for.. it will run for every 50 mili seconds and submit the form.. if you need it to call it once then use setTimeout
.
The setInterval() method calls a function or evaluates an expression at specified intervals (in milliseconds). The setInterval() method will continue calling the function until clearInterval() is called, or the window is closed.
reference: setInterval
The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds.
reference: setTimeout
Upvotes: 3