...

View Full Version : Minimum words in text area



tsclan
05-28-2004, 01:45 AM
I have seen a few javascripts that count the number of characters / letters like this http://www.felgall.com/jstip42.htm but what i would like is like a countdown where once you have writen more than 500 words it will let you post the item
some advice or help would be great thanks

Kor
05-28-2004, 07:33 AM
try this


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script>
function lung(f,k){
n=10;//number of max allowed characters
var v = new String();
s = k.split('');
for(i=0;i<n;i++){v += s[i]}
if(s.length>=n){f.elements['txt'].value=v;
f.elements['lun'].value = n-v.length;
}
else{f.elements['lun'].value = n-s.length;}
}
</script>
</head>
<body>
insert max. 10 characters
<form>
<textarea name="txt" cols="30" rows="2" onkeyup="lung(this.form,this.value)"onblur="lung(this.form,this.value)"></textarea>
<br>
available characters left:
<input name="lun" type="text" class="hideform" value="10" readonly="readonly">
</form>
</body>
</html>

Philip M
05-28-2004, 07:35 AM
You seem to have the word count script, so what is wanted
is simply

function checkwords (numberofwords) {
if (numberofwords <500) {
alert ("You must write 500 words before the form can be submitted");
return false;
}
return true
}

<form onSubmit= "checkwords(numberofwords)".....>

Kor
05-28-2004, 07:46 AM
...and for counting words (the previous code counts characters) try this:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script>
function lung(f,k){
n=10;//number of max allowed words
var v = new String();
s = k.split(' ');
for(i=0;i<n;i++){v += (s[i]+' ')}
if(s.length>=n+1){f.elements['txt'].value=v;
f.elements['lun'].value = n+1-v.length;
}
else{f.elements['lun'].value = n+1-s.length;}
if(f.elements['lun'].value==-9){f.elements['lun'].value=0}
}
</script>
</head>
<body>
insert max. 10 words
<form>
<textarea name="txt" cols="30" rows="2" onkeyup="lung(this.form,this.value)"onblur="lung(this.form,this.value)"></textarea>
<br>
available number of words left:
<input name="lun" type="text" class="hideform" value="10" readonly="readonly">
</form>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum