Letters counter

More
3 years 9 months ago #125885 by helviobrito
Letters counter was created by helviobrito
Hi. I'd like to include a counter in text fields of limited sizes. For example: in a text question for 300 characters, a counter starts in 300 and, as respondent write, the counter shows number of characters are left till the end. Can anyone provide a solution?

Please Log in or Create an account to join the conversation.

More
3 years 9 months ago #125887 by holch
Replied by holch on topic Letters counter
This is more a general web development question (javascript) rather than a Limesurvey question:

www.sitepoint.com/10-jquery-wordtext-counter-plugins/

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in or Create an account to join the conversation.

More
3 years 9 months ago - 3 years 9 months ago #125888 by Ben_V
Replied by Ben_V on topic Letters counter
For a text question with question code "qtext" (200 chars. max.):

try to place in the help area of this question
count: {strlen(self)}
left: {sum(200 - strlen(self))}

for other place try:
count: {strlen(qtext)}
left: {sum(200 - strlen(qtext))}

BTW, all EM functions are listed here :)

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Last edit: 3 years 9 months ago by Ben_V.
The following user(s) said Thank You: DenisChenu, holch, first

Please Log in or Create an account to join the conversation.

More
3 years 9 months ago #125896 by holch
Replied by holch on topic Letters counter
Hey Ben, thank you. This works great (only tried it with the "self" version).

@Helviobritto: No need to go for a plugin. LS has this onboard solution which works great and in real time.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in or Create an account to join the conversation.

More
3 years 9 months ago #125907 by Ben_V
Replied by Ben_V on topic Letters counter
I suppose there is some way to change the number color when you are near or pass the limit, something like green -> orange -> red ...

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)

Please Log in or Create an account to join the conversation.

More
1 month 3 days ago #185521 by Mazi
Replied by Mazi on topic Letters counter
Using the integrated Limesurvey Expression Manager functions is indeed the best approach. We have documented the full approach at this blog post: " How to count the number of characters entered at a Limesurvey text question ". It also shows how to limit the number of characters and how to reference the character count at other questions.

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com
Want to use your survey offline -> www.offlinesurveys.com

Please Log in or Create an account to join the conversation.

More
1 month 3 days ago #185540 by holch
Replied by holch on topic Letters counter
@Mazi: Saw your post and tried your sample survey. Looks good. But I was able to send a text with 165 characters (according to your count). What happened?

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in or Create an account to join the conversation.

More
1 month 3 days ago #185546 by Mazi
Replied by Mazi on topic Letters counter
I also noticed that when entering some dummy characters. It tuend out that character like "<" had not been counted. Could it have been a similar case? If you just enter the same character 160 times it works fine.

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com
Want to use your survey offline -> www.offlinesurveys.com

Please Log in or Create an account to join the conversation.

More
1 month 3 days ago #185547 by holch
Replied by holch on topic Letters counter
I did not use any special characters, if I recall right (just have a look at the last result in your Demo and you'll see my text). ;-)

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in or Create an account to join the conversation.

More
1 month 3 days ago #185548 by holch
Replied by holch on topic Letters counter
Here another test. I inserted this text until the text field wouldn't allow any further text.

This is a text with more than 160 characters. Let's see if it works now as expected. It should not be possible to insert more than 160 characters, but last time


Here what your Demo shows me:


I copied and pasted the text into Word and it counted only 160 characters, just like Limesurvey did, but your function counted 165 characters...

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds
Attachments:

Please Log in or Create an account to join the conversation.

More
1 month 3 days ago #185549 by holch
Replied by holch on topic Letters counter
I think I found the vilain. It is the ' (apostrophe).

When you insert "Let" it counts 3 characters, just as it should. If you add the apostrophe and have something like "Let'" it jumps to 9, so the apostrophe counts as 6 characters. Let's is 10 characters.

So this would explain that your count counts 165 characters, when Limesurvey stops at 160 characters. So the error is in the function "strlen" somewhere I guess?

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in or Create an account to join the conversation.

More
1 month 3 days ago #185551 by Mazi
Replied by Mazi on topic Letters counter
Yes, I think so, but it is not really a bug: "strlen() returns the number of bytes rather than the number of characters in a string."
-> www.php.net/manual/en/function.strlen.php

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com
Want to use your survey offline -> www.offlinesurveys.com

Please Log in or Create an account to join the conversation.

More
1 month 3 days ago #185552 by holch
Replied by holch on topic Letters counter
Well, then it is not a bug in strlen, but then it is a bug in your approach. ;-)

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in or Create an account to join the conversation.

More
1 month 3 days ago #185572 by DenisChenu
Replied by DenisChenu on topic Letters counter
If we use www.php.net/manual/fr/function.mb-strlen.php in PHP, need a mb_strlen in javascript …
Or maybe our JS have an issue

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand .
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in or Create an account to join the conversation.

More
1 month 3 days ago #185580 by Mazi
Replied by Mazi on topic Letters counter

holch wrote: I did not use any special characters, if I recall right (just have a look at the last result in your Demo and you'll see my text). ;-)


k, then let's call it a Limesurvey bug :-)

We have added a note about the special characters so users won't be confused.

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com
Want to use your survey offline -> www.offlinesurveys.com

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!