When submit the button goes inactive for 30 seconds

Discussion in 'JavaScript' started by human, Aug 25, 2008.

  1. #1
    How to make it ?
    I'm making an Ajax chat.There are my scripts:
    JS:
    function form() { 
       if(document.getElementById(form).style.display == 'block') { 
              document.getElementById(form).style.display = 'none'; 
             setInterval("form()",30000); 
       } 
       else { document.getElementById(form).style.display = 'block'; } 
       }
    Code (markup):
    HTML
    <div id="form" style="display:block;"> 
    The form
    </div>
    HTML:
    And the PHP script:
    echo "Success... 
    <script type=\"text/javascript\"> 
    form(); 
    </script>"; 
    PHP:

     
    human, Aug 25, 2008 IP
  2. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You have an error in your JS. It should be:
    function form() { 
       if(document.getElementById('form').style.display == 'block') { 
              document.getElementById('form').style.display = 'none'; 
             setInterval("form()",30000); 
       } 
       else { document.getElementById('form').style.display = 'block'; } 
       }
    Code (markup):
    cause you wanna access the element with id 'form'. What you've done is accessing the element with an id equal to the variable form, which may hold something else, or even be empty. Another way to do the same is to keep your code, but put the fallowing line before it:
    var form = 'form';
    Code (markup):
    This will work, but it's lame and unnecessary, cause this var will not be used for anything else..

    Just use my code and learn when to use ' and when not :)
     
    xlcho, Aug 27, 2008 IP
  3. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #3
    Use "setTimeout" instead of "setInterval".

    Other than that, I'm not quite sure what you're trying to accomplish just by looking at that code.
     
    joebert, Aug 29, 2008 IP