Hi Friends,
To count character count in a browsed file using javascript.Please follow the below code.
<html >
<head>
<script>
function cleartext(){
document.form_count.input.value = '';
document.form_count.char_count.value = '0';
document.form_count.c.value = '0';
document.form_count.s.value = '0';
document.form_count.line_count.value = '0';
document.form_count.custom_count.value = '0'}
function linecnt(){
setTimeout(linecnt2,100);}
function linecnt2(){
if(document.form_count.input.value.length > 0){
fc=document.form_count;
fc.line_count.value=fc.input.value.split(/\n/).length;}
else document.form_count.line_count.value = '0';}
function sentcnt(){
setTimeout(sentcnt2,100);}
function sentcnt2(){
var sentcont = document.form_count.input.value;
var belong2 = 'pbclevtug grkgzrpunavp.pbz';
sentcont = sentcont.replace(/\r/g,'');
sentcont = sentcont.replace(/ /g,' ');
sentcont = sentcont.replace(/ \n/g,'\n');
sentcont = sentcont + '\n';
sentcont1 = sentcont.split('. ').length -1;
sentcont1b = sentcont.split('.\n').length -1;
sentcont2 = sentcont.split('! ').length -1;
sentcont2b = sentcont.split('!\n').length -1;
sentcont3 = sentcont.split('? ').length -1;
sentcont3b = sentcont.split('?\n').length -1;
sentcontout = sentcont1 + sentcont1b + sentcont2 + sentcont2b + sentcont3 + sentcont3b;
document.form_count.s.value = sentcontout;}
function cuscnt(){
setTimeout(cuscnt2,100);}
function cuscnt2(){
if (document.form_count.case_sen.checked == true){var char=document.form_count.custom_count_query.value; var z=document.form_count.input.value;}
else {var char=document.form_count.custom_count_query.value.toLowerCase(); var z=document.form_count.input.value.toLowerCase();}
var charlen = char.length;
a=z.split(char);
if (charlen > 0) carcnt = a.length-1; else carcnt = "0";
document.form_count.custom_count.value = carcnt;}
function tolcnt(){
setTimeout(tolcnt2,100);}
function tolcnt2(){
if (document.form_count.no_spaces.checked == true){
var y=document.form_count.input.value;
var spacecnt=y.split(' ').length;
a=y.replace(/\n/g,'');
b=a.replace(/\r/g,'');
z=b.length-spacecnt;
document.form_count.char_count.value=z+1;} else{
var y=document.form_count.input.value;
a=y.replace(/\n/g,'');
b=a.replace(/\r/g,'');
z=b.length;
document.form_count.char_count.value=z;}}
function wrdcnt(){
setTimeout(wrdcnt2,100);}
function wrdcnt2(){
var y=document.form_count.input.value;
var r = 0;
a=y.replace(/\s/g,' ');
a=a.split(' ');
for (z=0; z<a.length; z++) {if (a[z].length > 0) r++;}
document.form_count.c.value=r;}
function SelectAll(id) {
document.getElementById(id).focus();
document.getElementById(id).select();}
function loadfile(){
var finput = document.getElementById('file2load');
var textarea2load = document.getElementById('input');
textarea2load.value = 'Loading...';
var redr = new FileReader();
redr.readAsText(finput.files[0]);
redr.onload = function(asdfg){textarea2load.value = asdfg.target.result;}}
</script>
</head>
<body onLoad="hgt=this.window.screen.availHeight-417; if(hgt>310)document.form_count.input.style.height=hgt+'px';">
<form style="margin-bottom: 0px; margin-top: 0px; font-size: 16px;" action="#" name="form_count">
<input class="buttn" value=" Count Text " onClick="tolcnt(document.form_count.input,document.form_count.char_count); wrdcnt(document.form_count.input,document.form_count.c); linecnt(); sentcnt(); cuscnt();" type="button"><input style="vertical-align: top;" title="" name="inst" checked="checked" type="checkbox">i
Characters <input style="width: 56px; margin: 0px; padding-left: 2px; background-color: rgb(0, 0, 0); color: rgb(255, 255, 255); font-weight: bold; font-size: 16px; font-family: arial; border: 0px none; vertical-align: middle;" name="char_count" value="713" readonly="readonly" type="text"><input style="vertical-align: top;" title="Do not count spaces." name="no_spaces" onClick="tolcnt(document.form_count.input,document.form_count.char_count);" type="checkbox">NS
Words <input style="width: 44px; margin: 0px; padding-left: 2px; background-color: rgb(0, 0, 0); color: rgb(255, 255, 255); font-weight: bold; font-size: 16px; font-family: arial; border: 0px none; vertical-align: middle;" name="c" value="118" readonly="readonly" type="text">
Sentences <input style="width: 44px; margin: 0px; padding-left: 2px; background-color: rgb(0, 0, 0); color: rgb(255, 255, 255); font-weight: bold; font-size: 16px; font-family: arial; border: 0px none; vertical-align: middle;" name="s" value="9" readonly="readonly" type="text">
Lines <input style="width: 44px; margin: 0px; padding-left: 2px; background-color: rgb(0, 0, 0); color: rgb(255, 255, 255); font-weight: bold; font-size: 16px; font-family: arial; border: 0px none; vertical-align: middle;" name="line_count" value="6" readonly="readonly" type="text">
<textarea name="input" id="input" style="width: 100%; height: 321px; margin-top: 3px; font-family: arial; font-size: 16px; overflow: scroll; border: 1px solid rgb(0, 0, 0);" wrap="off" onKeyUp="if(document.form_count.inst.checked==true){tolcnt(); wrdcnt(); linecnt(); sentcnt(); cuscnt();}" onpaste="if(document.form_count.inst.checked==true){tolcnt(); wrdcnt(); linecnt(); sentcnt(); cuscnt();}" spellcheck="false"></textarea></form>
<div style="margin-top: 3px;"><input id="file2load" onChange="loadfile(); tolcnt(document.form_count.input,document.form_count.char_count); wrdcnt(document.form_count.input,document.form_count.c); linecnt(); sentcnt(); cuscnt();" style="font-size: 10px; font-family: arial;" type="file">
</div>
</body>
</html>
May this helps you
