Hello Everyone, I am new to writing javascripts. I am working on a web-interface that has to show certain data in real-time (update it every 2 seconds). I figured including an iframe and reloading it with javascript would be the best bet. So to see if it works I wrote this test code. But it doesnt reload the iframe every 2 seconds. Can anyone point out where I am going wrong ? this is the code for hello1.php <html> <head> <script type="text/javascript"> function reloadIt() { var frm=document.getElementsByid("iframe1"); frm.src=frm.src; setTimeout("reloadIt()",1000); } </script> </head> <body onload="reloadIt()"> <h1>This is a test</h1> <p>The random integer is <iframe id="iframe1" name="iframe1" height="30" width="300" src="hello.php"></iframe> </p> </body> </html> PHP: and this is the code for hello.php <?php $i=rand(0,10); print ("$i"); ?> PHP: Any help with this would be highly appreciated. Thanks
try it this way and it will work. note the correct spelling of getElementById <html> <head> <script type="text/javascript"> function reloadIt() { document.getElementById("iframe1").src="hello.php"; var t=setTimeout("reloadIt()",1000); } </script> </head> <body onload="reloadIt()"> <h1 id="h1">This is a test 2</h1> <p>The random integer is <iframe id="iframe1" name="iframe1" height="30" width="400" src="hello.php"></iframe> </p> </body> </html> Code (markup):