String Length function in JavaScript

Length of a string can be calculated by using JavaScript length function. Here is an example of how to get length of a string.

var my_str="Hello world!"
document.write(my_str.length)// 12
Note that the command will count blank space also.

DEMO: Counting data entered by user


<script type="text/javascript">
function check_text1_length(){
var t1=document.getElementById("text1").value;
document.getElementById("msg").innerHTML="The length of data = " + t1.length;
}
</script>

<input type=text name=text1 id=text1>
<input type=button onclick=check_text1_length(); value=Check>
<div id=msg></div>

JavaScript String Reference Changing letters by toUpperCase() method
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Nibedita Sahu

    18-01-2011

    How to remove blank spaces between two characters using javascript

    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer