|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Word Count
Anyone have sample on Word Count.
There is a context box. And while the user typing into the box, the other box count and minus the character. The count box may have a initial value of 200, and it getting less while the user typing. |
|
#2
|
||||
|
||||
|
You can use the textbox or textarea's events, such as onChange. When the user types in a letter, a javascript function is called and it re-calculates the word count and updates the count box.
<textarea name="adtext" rows="8" cols="62" onChange="javascript:setTextCount();"></textarea> The setTextCount function would get called each time the user enters a character. It would count of the text, peform the calculation, then update the count textbox. |
|
#3
|
|||
|
|||
|
but I need the script of javascript:setTextCount() in order to call it.
I do not know how to write the script to make it count n minus. |
|
#4
|
||||
|
||||
|
The most reliable way to do this is to count how many characters the user has typed in, each time something in the textbox changes. Assuming your textboxes are called txtType and txtCount and your form is called form1, your function would look something like this below:
function setTextCount() { var nCurCount = document.form1.txtCount.value; var nCnt = document.form1.txtType.value.length; document.form1.txtCount.value = ( nCurCount - nCnt ); } Your textbox would look like this: <form name="form1"> <input type="text" name="txtType" onChange="setCount()"> </form> |
|
#5
|
|||
|
|||
|
It works, Tq very much
![]() |
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > Word Count |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|