Reputation: 445
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;
}
Upvotes: 0
Views: 67
Reputation: 1
You can use the setTimeout
function:
setTimeout("your function to be called to activate an email form", 6000);
Upvotes: 0
Reputation: 4015
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>
Upvotes: 1
Reputation: 22105
Use setTimeout.
window.setTimeout(function() {
// Do whatever you need
}, 6000);
Upvotes: 1