Skip to main content
Level 2
February 19, 2021
Solved

Word Count result while typing, rather than on exit

I have a form where a field is limited as to the number of words.

I found a JavaScript that does what I need as far as giving me a Word Count, however it will only show the results on exit, not while the user is typing.

I've tried changing the event to "change" or "enter" and other options, but that breaks the code.

How can I fix it so it gives me live updates?

 

Any help would be greatly appreciated.

Thanks.

 

The code is currently:

var cnt = word_count(this.rawValue); WordCountResult.rawValue = cnt.toString(); function word_count(textParam) { textParam = textParam.replace(/^\s*|\s*$/g,''); if (textParam) return textParam.split(/\s+/).length; else return 0; }
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Kosta_Prokopiu1
Kosta_Prokopiu1Accepted solution
Adobe Employee
February 22, 2021

Place your function in the change event. Then call as word_count(xfa.event.fullText); this.rawValue will not work in this context.

4 replies

Mayank_Gandhi
Adobe Employee
Adobe Employee
February 22, 2021

Are you rendering as HTML or pdf?

Translate
Level 2
February 22, 2021
As a PDF
Translate
Kosta_Prokopiu1
Adobe Employee
Kosta_Prokopiu1Adobe EmployeeAccepted solution
Adobe Employee
February 22, 2021

Place your function in the change event. Then call as word_count(xfa.event.fullText); this.rawValue will not work in this context.

Translate
Level 2
February 22, 2021
Thank you! this worked!
Translate