Thursday, October 24, 2013

Jquery to Get Length(count of characters) in a String

Leave a Comment
Jquery 'length' property can be used to get the number of characters in a string. In this example the jquery script would display number of characters entered inside asp.net textbox control on the click of a button.

Jquery to Fetch the Length of a string:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$(function () {
         $('#btngettext').click(function (e)
                { var GetValue = $('#txtname').val();
                    alert(GetValue.length);
                });
            });

        });
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" ID="txtname"></asp:TextBox>
<asp:Button runat="server" ID="btngettext" Text="Display" />
</div>
</form>
</body>
</html>

0 comments:

Post a Comment