WEB TECH lab

 <html>


<head>
    <title>Number in word</title>
    <script>
        function convert() {
            var num = document.forms["frm1"].num.value;
            document.forms["frm1"].words.value = "";
            if (isNaN(num)) {
                alert("Please enter a number");
            } else if (num < 0 || num > 999) {
                alert("Please enter a number between 0 and 999");
            } else {
                var len = num.length;
                var words = "";
                for (var i = 0; i < len; i++) {
                    var n = num.charAt(i);
                    switch (n) {
                        case '0': words += "zero "; break;
                        case '1': words += "one "; break;
                        case '2': words += "two "; break;
                        case '3': words += "three "; break;
                        case '4': words += "four "; break;
                        case '5': words += "five "; break;
                        case '6': words += "six "; break;
                        case '7': words += "seven "; break;
                        case '8': words += "eight "; break;
                        case '9': words += "nine "; break;
                        default: break;
                    }
                }
                document.forms["frm1"].words.value = words.trim();
            }
        }

    </script>
</head>

<body>
    <h1 align="center">Number in word</h1>
    <form name="frm1" method="post" action="exp44.html">
        <table align="center" border="0" cellpadding="5" cellspacing="5">
            <tr>
                <td>Enter a number:</td>
                <td><input type="text" name="num"></td>
            </tr>
            <tr>
                <td>Number in words:</td>
                <td><input type="text" name="words"></td>
            </tr>
            <tr>
                <td colspan="2" align="center"><input type="button" value="Convert" onclick="convert()"></td>
            </tr>
        </table>
    </form>


</body>

</html>

Comments

Popular posts from this blog

C-Programming of Class 12

C-Program of Class 11