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
BedrockMission!

Learn More

View all

Sign in to view all badges

Word Count result while typing, rather than on exit

Avatar

Avatar
Validate 1
Level 1
fogharty
Level 1

Likes

0 likes

Total Posts

17 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
fogharty
Level 1

Likes

0 likes

Total Posts

17 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
fogharty
Level 1

19-02-2021

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;
}

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Affirm 100
Employee
Kosta_Prokopiu1
Employee

Likes

165 likes

Total Posts

369 posts

Correct Reply

107 solutions
Top badges earned
Affirm 100
Validate 1
Establish
Give Back 5
Give Back 3
View profile

Avatar
Affirm 100
Employee
Kosta_Prokopiu1
Employee

Likes

165 likes

Total Posts

369 posts

Correct Reply

107 solutions
Top badges earned
Affirm 100
Validate 1
Establish
Give Back 5
Give Back 3
View profile
Kosta_Prokopiu1
Employee

22-02-2021

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

Answers (1)

Answers (1)

Avatar

Avatar
Springboard
Level 10
Mayank_Gandhi
Level 10

Likes

327 likes

Total Posts

1,150 posts

Correct Reply

185 solutions
Top badges earned
Springboard
Establish
Validate 1
Contributor 2
Ignite 5
View profile

Avatar
Springboard
Level 10
Mayank_Gandhi
Level 10

Likes

327 likes

Total Posts

1,150 posts

Correct Reply

185 solutions
Top badges earned
Springboard
Establish
Validate 1
Contributor 2
Ignite 5
View profile
Mayank_Gandhi
Level 10

22-02-2021

Are you rendering as HTML or pdf?