Auto Click Function Continuously Clicking On Submit Button
I have put auto click function on my form. I want to auto click submit button only once. But my code is continuously clicking on submit button. Due to that my page is continuously
Solution 1:
You can use localstorage to determine if you have already submitted the form or not, and submit the form based on this value
window.onload = function(){
if (localStorage.formSubmitted !== 'true') {
localStorage.setItem("formSubmitted", "true");
document.getElementById('btn').click();
}
}
Solution 2:
The two answers given are good, however users can manipulate and mess with these stored session items and therefore allows for manipulation of validation.
To avoid users messing with your validation you can check if the form has been posted in PHP. This is especially important when dealing with sensitive user information.
<?phpif(!isset($_POST['submit'])) { ?><script>window.onload = function ()
{
document.getElementById('btn').click();
}
</script><?php } ?>
Solution 3:
You can also store it in localstorage when the button is clicked for the first time. And before you execute the click event, check if that storage is set. Like this:
window.onload = function() {
if (!localStorage.getItem('buttonClicked')) {
localStorage.setItem('buttonClicked', 'true');
document.getElementById('btn').click();
}
}
Post a Comment for "Auto Click Function Continuously Clicking On Submit Button"