yiannakop
February 11th, 2005, 08:55 AM
Hi everyone. I am completely new to ASP (I now some jsp and I think they are quite similar). I have this question: I have a text area and I want to count the number of words written in that area and also this number to be displayed in another text area.
Plz help.
Thanx in advance :)
Dr. Script
February 11th, 2005, 03:07 PM
ASP is a server side language. It would require you to submit a form, go to a new page, display the text and number of words. Using JavaScript would be easier, and it could do it on the spot:<script type="text/javascript">
function cntWrds(obj,nom) {
var val = obj.value.replace(/\s{2,}/g,' ');
var amt = val.split(' ').length;
document.getElementById(nom).value = amt;
}
</script>
<p>
Text:
<textarea style="width:400px;height:100px;" name="words" onkeyup="cntWrds(this,'amt')"></textarea>
</p>
<p>
Amount of Words:
<input type="text" id="amt" value="0">
</p>Dr. Script