I have this Code:
<html>
<form method="POST">
<textarea name="txt" value="" rows="5" cols="100"></textarea>
<br></br>
<input type="button" name="" value="Message" onClick="btfunc()" style="width:100; height:100" wrap="soft">
</form>
<script charset="utf-8">
var strs = ["C++", "Python"];
var i = 0;
var strpos = 0;
function btfunc()
{
while (i < strs[strpos].length)
{
if (strpos > strs.length - 1)
{
break;
}
else
{
if (i == strs[strpos].length - 1)
{
document.forms[0].elements[0].value += strs[strpos].charAt(i);
i = -1;
strpos++;
document.forms[0].elements[0].value += "\n";
i++;
setTimeout(btfunc, 2000);
}
else
{
document.forms[0].elements[0].value += strs[strpos].charAt(i);
i++;
setTimeout(btfunc, 100);
}
}
}
}
</script>
</html>
When I Click On The Button It Inserts All Text Without Going Pausing In SetTimeouts, Why Does It Happen?