I'm currently a beginner at JavaScript and predominantly code in Java.
My Question is is regarding invoking the document.write("string here")
periodically (every 1/2 seconds) to append any new unprinted chat message to the client. I earlier tried using the following code :
<html>
<body onload="yantra();">
<script type="text/javascript">
x = 0;
function yantra(){
document.write("Hello<br>");
i = 1;
for(i = 0; i < 100; i++){
setTimeout("writeOneNum()", 1000);
}
}
function writeOneNum(){
x =x + 1;
document.write(x+"<br>");
}
function blank(){}
</script>
</body>
</html>
Instead of it printing 1 to 100 every 1000 millisecond as I expected it to print; in actuality, it printed 1 to 100 at one go (meaning without any delay).