Prev Demo
JavaScript
>
How To Get The Length Of The String In Javascript?
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Length of a string</h1> Enter name: <input type="text" id="txtName" name="txtName" /> <input type="button" id="btnsm" value="Get Length" onclick="GetLength()" /> <script> function GetLength() { var text = document.getElementById("txtName").value; alert(text.length); } </script> <p><strong>Note:</strong> Enter text and click on the button to know the length of the entered text.</p> </body> </html>
Note: We DO NOT save your trial code in our database.
Output