- Posts: 55
- Thank you received: 1
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Only one character allowed
- Vinicos
- Topic Author
- Offline
- Senior Member
Less
More
3 years 8 months ago #203768
by Vinicos
Only one character allowed was created by Vinicos
Hello
I have created a multiple short text question with 3 subquestions. I want the first and the third subquestion to allow only one-character answers. I have already used a subquestion validation equation, but I actually want that the field accepts only one character (just like when we set a maximum of character in a numeric question). Is this possible?
Thanks
LS 3.22
I have created a multiple short text question with 3 subquestions. I want the first and the third subquestion to allow only one-character answers. I have already used a subquestion validation equation, but I actually want that the field accepts only one character (just like when we set a maximum of character in a numeric question). Is this possible?
Thanks
LS 3.22
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10110
- Thank you received: 3594
3 years 8 months ago #203771
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Only one character allowed
Place this script in the question source:
Sample survey attached:
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // First input $('#question{QID} input:text:eq(0)').attr('maxlength', 1); // Third input $('#question{QID} input:text:eq(2)').attr('maxlength', 1); }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- Vinicos
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 55
- Thank you received: 1
3 years 8 months ago #203772
by Vinicos
Replied by Vinicos on topic Only one character allowed
Thanks a lot.
It works well.
Is it also possible to allow participants only to use letters (not as a question validation equation)?
It works well.
Is it also possible to allow participants only to use letters (not as a question validation equation)?
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10110
- Thank you received: 3594
3 years 8 months ago #203774
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Only one character allowed
This will also remove all non-alpha characters:
Sample survey attached:
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // First input $('#question{QID} input:text:eq(0)').attr('maxlength', 1); // Third input $('#question{QID} input:text:eq(2)').attr('maxlength', 1); // Listener on inputs $('#question{QID} input:text:eq(0), #question{QID} input:text:eq(2)').on('keyup', function(e) { var thisValue = $.trim($(this).val()); // Strip out non-alpha characters newValue = thisValue.replace(/\W/g,'').replace(/\d/g,''); $(this).val(newValue).trigger('change'); }); }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- Vinicos
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 55
- Thank you received: 1
3 years 8 months ago #203775
by Vinicos
Replied by Vinicos on topic Only one character allowed
Sorry to bother again.
But, in this case, I would like the three subquestions to allow only letters. The first and the third only one character, but the second as much as the participants want (but only letters). Would the syntax be different then?
But, in this case, I would like the three subquestions to allow only letters. The first and the third only one character, but the second as much as the participants want (but only letters). Would the syntax be different then?
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10110
- Thank you received: 3594
3 years 8 months ago - 3 years 8 months ago #203776
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Only one character allowed
Change:
To:
Code:
$('#question{QID} input:text:eq(0), #question{QID} input:text:eq(2)').on('keyup', function(e) {
To:
Code:
$('#question{QID} input:text').on('keyup', function(e) {
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 3 years 8 months ago by tpartner.
The topic has been locked.
- Vinicos
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 55
- Thank you received: 1
3 years 8 months ago #203829
by Vinicos
Replied by Vinicos on topic Only one character allowed
Thanks. It works perfectly now.
The topic has been locked.