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?
JavaScript
x
17
17
1
var inActive = true;
2
3
function inActive() {
4
if (!inActive)
5
return true;
6
7
inActive = true;
8
document.getElementById("myForm").disabled = true;
9
10
setTimeout(function() {
11
inActive = true;
12
document.getElementById("myForm").disabled = false;
13
}, 1000);
14
15
return true;
16
}
17
Advertisement
Answer
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.
JavaScript
1
22
22
1
<script type="text/javascript">
2
window.onload = function(){
3
var inActive = true;
4
5
function inActivate() {
6
if (!inActive)
7
return true;
8
9
inActive = true;
10
document.getElementById("myForm").disabled = true;
11
12
setTimeout(function () {
13
inActive = true;
14
document.getElementById("myForm").disabled = false;
15
}, 4000);
16
17
return true;
18
}
19
inActivate();
20
};
21
</script>
22