How do i make a Javascript that will make so when i press my submit button it will change the name of the button to something like this "Loading..." and after 3 sec the button should be pressed
<input type="Submit" name="submitNew" id="submitNew" value="Send">
It will act as an "spam filter" for humans..
How do i make a Javascript that will make so when i press my submit button it will change the name of the button to something like this "Loading..." and after 3 sec the button should be pressed
<input type="Submit" name="submitNew" id="submitNew" value="Send">
It will act as an "spam filter" for humans..
Share Improve this question asked Nov 30, 2012 at 22:05 Hannes Brolin LagerstedtHannes Brolin Lagerstedt 874 silver badges12 bronze badges 3- That's not a great way to prevent spam... – Brad Commented Nov 30, 2012 at 22:07
- Define "spam filter". If you are worrying about bots this will fail, because they will not have JS enabled in most cases. – PeeHaa Commented Nov 30, 2012 at 22:08
- You have to use a timer w3schools./js/js_timing.asp the on mouse down will put a flag somewhere and start the timer, on mouse up will remove this flag and stop the timer. If once the timer is fired the flag is present, then you know that you pressed the mouse all the time long. – Flavien Volken Commented Nov 30, 2012 at 22:08
2 Answers
Reset to default 7One possible solution is to set submit
event for form
element in the following way:
HTML:
<form onsubmit="return formSubmit(this);">
JavaScript:
function formSubmit(form) {
document.getElementById("submitNew").value = "Loading...";
setTimeout(function() {
form.submit();
}, 3000); // 3 seconds
return false;
}
Another way is to set the event dynamically (tribute to the kittens!):
window.onload = function() {
document.getElementById("formID").onsubmit = function() {
var form = this;
document.getElementById("submitNew").value = "Loading...";
setTimeout(function() {
form.submit();
}, 3000); // 3 seconds
return false;
};
};
DEMO: http://jsfiddle/spWDk/
You can try the below solution:
<form action="https://google." method="post" name="simulation" id="simulation">
<input type="text" name="nom" id="nom"/>
<input type="text" name="prenom" id="prenom"/>
<input type="submit" value"Submit">
</form>
<script>
$("#simulation").on('submit', function (e) {
console.log("Submitted");
//stop form submission
e.preventDefault();
//Do your custom work.
setTimeout(function(){ document.getElementById('simulation').submit(); }, 5000);
});
</script>