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:
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
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.