How can I get the length of text entered in a textbox using jQuery?
How can I get the length of text entered in a textbox using jQuery?
var myLength = $("#myTextbox").val().length;
If your textbox has an id attribute of "mytextbox", then you can get the length like this:
var myLength = $("#mytextbox").val().length;
-
$("#mytextbox")
finds the textbox by its id. -
.val()
gets the value of the input element entered by the user, which is a string. -
.length
gets the number of characters in the string.
For me its not text box its a span tag and this worked for me.
var len = $("span").text().length;
Below mentioned code works perfectly fine for taking length of any characters entered in textbox.
$("#Texboxid").val().length;