'Deactivating and activating an E-mail form
I'm trying to get the code below to keep an E-mail form deactivated until 6 seconds after the page is fully loaded. What can I do to make it work like that?
var inActive = true;
function inActive() {
if (!inActive)
return true;
inActive = true;
document.getElementById("myForm").disabled = true;
setTimeout(function() {
inActive = true;
document.getElementById("myForm").disabled = false;
}, 1000);
return true;
}
Solution 1:[1]
It is not a good idea to hard code the duration. Instead you should call the activate using asynchronous call.
Anyways, here is the working code.
<script type="text/javascript">
window.onload = function(){
var inActive = true;
function inActivate() {
if (!inActive)
return true;
inActive = true;
document.getElementById("myForm").disabled = true;
setTimeout(function () {
inActive = true;
document.getElementById("myForm").disabled = false;
}, 4000);
return true;
}
inActivate();
};
</script>
Solution 2:[2]
Solution 3:[3]
You can use the setTimeout
function:
setTimeout("your function to be called to activate an email form", 6000);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Sandeep G B |
Solution 2 | pradeek |
Solution 3 | sj26 |