[Solved] Javascript get user input from textbox

Javascript get user input from textbox 

In this tutorial, we will discuss how to get user input from textbox using javascript, this pretty simple process to achieve it. Here you will see the process of getting value from HTML textbox and asp.net textbox.


Javascript get user input from textbox

For HTML Control


<!DOCTYPE html>

<html>

<head>

<title>get user input from textbox</title>

<script>

    function GetValue() {

        var myval = document.getElementById("myText").value;

        alert(myval);

    }

</script>

</head>

<body>

Text Box

<input type="text" id="myText" value="">

<p>Click the button to get user input</p>

<button onclick="GetValue()">Check</button>

</body>

</html>


For Asp.net Control


If you are a .net developer, many time the same requirement comes in Asp.net Application.

<!DOCTYPE html>

<html>

<head>

<title>get user input from textbox</title>

<script>

    function GetValue() {

        var myval = document.getElementById('<%= txt_name.ClientID %>').value;            alert(myval);

    }

</script>

</head>

<body>

Name:

<asp:TextBox ID="txt_name" runat="server" > </asp:TextBox>

 

<p>Click the button to get user input</p>

<button onclick="GetValue()">Check</button>

</body>

</html>

 

In the above example getElementById() is a kind of method which is used to return the that has ID. If you have any doubt, feel free to comment below.



Post a Comment

Post a Comment (0)

Previous Post Next Post