Java script for loop is same like our programming language C and C++ and C#
Code Sample :
<html>
<head>
<title>for loop example in Javascript</title>
<script language="Javascript">
function shownumbers() {
var count = parseInt(document.getElementById("txtcount").value);
for (var i = 0; i < count; i++)
alert(i + 1);
}
</script>
</head>
<body>
<table align="center">
<tr>
<td>
<input type="text" id="txtcount" />
</td>
</tr>
<tr>
<td>
<input type="button" id="btnShow" onclick="shownumbers();" value="Show Numbers" />
</td>
</tr>
</table>
</body>
</html>O/P :
we entered 3 in the text box so the count is 3 and we are getting 3 alerts
No comments:
Post a Comment