Posted by : Sudhir Chekuri Thursday, 17 October 2013

I used two html inputs in this example. They are textbox and a button.
id for textbox is txt1 and it is used to get its value using javascript code.
value entered in texbox txt1 is saved in variable a and then it is displayed in alert box using function f1.
onclick event is fired when user click on a button to execute javascript code written inside function f1.

HTML and Javascript code to display text entered by user in alert box

<html>
<head>
    <script type="text/javascript" >
        function f1()
        {
            var a = document.getElementById("txt1").value;
            alert(a);
        }
    </script>
</head>

<body>
    <input type="text" id="txt1"/>
    <br/>
    <input type="button" value="Click" onclick="f1()"/>
</body>
</html>

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Followers

Total Pageviews

Powered by Blogger.

Blog Archive

- Copyright © 2013 DevStudent - Metrominimalist - Powered by Blogger - Designed by Johanes Djogan -