In this article I am going to explain how to get the Length of Text box text, Value of Text box control and change the value of text box value using Jquery Code.
val() function is used to get the value of text box value.
val().length used to get the length of text entered in the text box.
val('some text') used to change the text box value.
Jquery Code along with HTML to Get Asp.net Text Box Value, Get Length of Text Box Value and Change Value of Text Box :
val() function is used to get the value of text box value.
val().length used to get the length of text entered in the text box.
val('some text') used to change the text box value.
Jquery Code along with HTML to Get Asp.net Text Box Value, Get Length of Text Box Value and Change Value of Text Box :
<%@
Page Language="C#" AutoEventWireup="true" CodeFile="textbox.aspx.cs" Inherits="textbox" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD
XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="//code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
//Get
text box value
$('#Button1').click(function () {
var
textvalue = $('#txtName').val();
alert(textvalue);
});
//Get
Length of Text Box
$('#Button2').click(function () {
var
textvaluelen = $('#txtName').val().length;
alert(textvaluelen);
});
//Change
the Text Box Value
$('#Button3').click(function () {
var
changetext = $('#txtName').val('Sohan Kumar');
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtName" runat="server" Text="Sumit Sharda" ></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Get Text Box Value" ClientIDMode="Static"
/>
<br />
<asp:Button ID="Button2" runat="server"
Text="Get Lenth of
Text" ClientIDMode="Static" />
<br/>
<asp:Button ID="Button3" runat="server" Text="Change Text Box Value" ClientIDMode="Static"
/>
</div>
</form>
</body>
</html>
0 comments:
Post a Comment