Finding the length of characters in text area using basic javascript and HTML.
Javascript Program
<html>
<head>
<title>Length Of Character</title>
</head>
<script type="text/javascript">
function len(){
var result;
var a=document.getElementById('myValue').value;
if( a == 0){
result="Please insert caharacter"
}
else{
result=document.getElementById('demo').innerHTML=a.length;
}
document.getElementById('demo').innerHTML=result;
}
</script>
<body>
<h1>Enter character</h1>
<textarea rows="4" cols="50" name="comment" id="myValue">
Enter text here...</textarea><br><br>
<input type="submit" onclick="len()">
<H2>CHARACTER LENGTH IS =<span id="demo" style="color:red;"></span></H2>
</body>
</html>
</body>
</html>
Note: It also considers space in counting for eg. if you insert value like JOHN MIKE it will show you result as 9 though it is only 8 words because it also considers space between words in counting.
OUTPUT
No comments:
Post a Comment