Form automatic submit does not work well, because the form is sent several times

19 Views Asked by At

The goal I had set myself was to send the form automatically after X time had passed. The code I put down creates the send at regular intervals as if you had used the function: setInterval. I don't understand why the setTimeout function works the same as the setInterval. Do you have any ideas?

setTimeout(function() {submitForm();}, 2000);
function submitForm(){
    document.getElementById("form").submit();
}

PHP/HTML form:

echo '<div class="search" id="searching" style=" align=center">';
echo "<form name=\"input\" id=\"form\" action=\"$targetpage\" method=\"get\" target=\"framedxup\">";
    
echo SEARCH_TXT . "  <input type=\"text\" value=\"$srch\" autocomplete=\"off\" name=\"searchterm\">";
echo " <input type=\"submit\" id=\"button\" name=\"button\" value=\"Search\">";
0

There are 0 best solutions below