Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Word Count result while typing, rather than on exit

fogharty
Level 2
Level 2

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;
}
1 Accepted Solution
Kosta_Prokopiu1
Correct answer by
Employee
Employee

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

View solution in original post

4 Replies
Kosta_Prokopiu1
Correct answer by
Employee
Employee

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

View solution in original post