Any reason not to use AJAX I wonder?
With it, you can request or submit info without leaving the current page. In this case, it sounds ideal. We can programmatically fill input(s) on the form, submit it, change elements and submit it again - as many times as we please.
Here's a quick'n'dirty sample implementation.
It prints to the console 10 times.
0
1
2
3
4
5
6
7
8
9
1. FormAction.html
<!DOCTYPE html>
<html>
<head>
<script>
"use strict";
function byId(id){return document.getElementById(id);}
function myAjaxPostForm(url, formElem, successCallback, errorCallback)
{
var ajax = new XMLHttpRequest();
ajax.onreadystatechange = function()
{
if (this.readyState==4 && this.status==200)
successCallback(this);
}
ajax.onerror = function()
{
console.log("AJAX request failed to: " + url);
errorCallback(this);
}
ajax.open("POST", url, true);
var formData = new FormData(formElem);
ajax.send( formData );
}
////////////////////////////////////////////////////////////////////////////////
window.addEventListener('load', onDocLoaded, false);
function onDocLoaded(evt)
{
byId('goBtn').addEventListener('click', onGoBtn, false);
}
var curIter = 0, maxIter=10;
function onGoBtn(evt)
{
byId('numberIn').value = curIter;
myAjaxPostForm('formAction.php', byId('mForm'), onAjaxDone);
function onAjaxDone(ajax)
{
console.log(ajax.responseText);
curIter++;
if (curIter < maxIter)
{
byId('numberIn').value = curIter;
myAjaxPostForm('formAction.php', byId('mForm'), onAjaxDone);
}
}
}
</script>
<style>
</style>
</head>
<body>
<button id='goBtn'>GO!</button>
<form id='mForm'>
<input type='number' id='numberIn' name='numberIn'/>
</form>
</body>
</html>
2. FormAction.php
<?php
echo $_POST['numberIn'] . "\n";
?>