Menu ▼

Previous Next

For loop in javascript :

Syntax :    for(var i=0;i<10;i++)
                     alert(i+1);

Enter Number:


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>

 

 

Previous Next




Search dotnetlearners.com