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