Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Character Limit for 'Other' Option

More
9 years 4 months ago #134861 by BBCMResearch
Hi,

I have a couple of multiple choice questions in my survey that have "Other" Options at the end. My client wants these options to be limited to no more than 150 characters, however I can't figure out where/if I can set a character limit.

Advice?
The topic has been locked.
More
9 years 4 months ago #135042 by first
jsfiddle.net/pioul/ysC7L/

I little google search is always helpful...

Survey Designer and Programmer
The following user(s) said Thank You: BBCMResearch
The topic has been locked.
More
9 years 4 months ago #135070 by tpartner
You can add something like this to the question source:

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function() {
    $('#question{QID} input.text').attr('maxlength', '150');
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: BBCMResearch, nique
The topic has been locked.
More
9 years 4 months ago #135089 by BBCMResearch
Thank you both!
The topic has been locked.
More
8 years 4 months ago #153380 by nique
Apologies for asking this on an old thread, but is it possible to add this to a List - Other option?

I have used the other script for Multiple choice questions and it works great! But it does not appear to work for a dropdown list.

Thanks in advance for any help.
The topic has been locked.
More
8 years 4 months ago #153407 by tpartner
Try this:

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function() {
    $('#question{QID} input[type="text"]').attr('maxlength', '150');
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: nique
The topic has been locked.
More
8 years 4 months ago #154147 by nique
Thank you! Works a treat.

Am I correct in assuming that this - [type="text"] - identifies the specific Other text input?
The topic has been locked.
More
8 years 4 months ago #154167 by tpartner
Yes, the [type="text"] selector will target all short-text inputs in that question. Those inputs normally have an associated class "text" (used in the previous workaround) but that class seems to have been omitted in this question type.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: nique
The topic has been locked.
More
8 years 1 month ago #156914 by DenisChenu
To be sure it woirk without javascript (never trust user):
Code:
strlen(Multi_other.NAOK) < 150
in em_validation_q www.limesurvey.org/manual/Question_type_...28em_validation_q.29

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
More
5 years 3 months ago - 5 years 3 months ago #200276 by reginab
Sorry added in duplicate by mistake
Last edit: 5 years 3 months ago by reginab.
The topic has been locked.
More
5 years 3 months ago - 5 years 3 months ago #200277 by reginab
Hi,
I have tried this out but can't seem to get it working, I wonder would you mind taking a look?
Here is my question:(see Capture1.png)
It is called q313_other (see Capture2.png)
Here is the code I added:(see Capture3.png)
However I can add more than 4 chars (see Capture4.png)



Any help would be much appreciated

Thanks,
R
Last edit: 5 years 3 months ago by reginab.
The topic has been locked.
More
5 years 3 months ago #200279 by tpartner
Change:
Code:
input.text

To:
Code:
input[type="text"]

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
5 years 3 months ago - 5 years 3 months ago #200286 by reginab
Thanks for the reply - I've changed it to :

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#question{q313_other} input[type="text"]').attr('maxlength', '4');
});
</script>

But no joy, it's still not working
Last edit: 5 years 3 months ago by reginab.
The topic has been locked.
More
5 years 3 months ago - 5 years 3 months ago #200287 by tpartner
Change:
Code:
$('#question{q313_other} input[type="text"]')

To:
Code:
$('#question{QID} input[type="text"]')

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 5 years 3 months ago by tpartner.
The topic has been locked.
More
5 years 3 months ago #200288 by reginab
That fixed it, thanks a million :-)
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose