Skip to content
Advertisement

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;
   }

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.

<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>
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement