- Posts: 10098
- Thank you received: 3589
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Make "Submit" button appear only if people answer "Yes" for a Yes/No question
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
5 years 2 weeks ago #182689
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 Make "Submit" button appear only if people answer "Yes" for a Yes/No question
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- terryaulenbach
- Offline
- Junior Member
Less
More
- Posts: 37
- Thank you received: 1
5 years 2 weeks ago #182694
by terryaulenbach
Replied by terryaulenbach on topic Make "Submit" button appear only if people answer "Yes" for a Yes/No question
Thank you as always, Tony. I have been searching and searching for this but that article never materialised for me. I owe you a virtual beer.
The topic has been locked.
- krosser
- Offline
- Elite Member
Less
More
- Posts: 222
- Thank you received: 10
5 years 1 week ago - 5 years 1 week ago #182942
by krosser
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Replied by krosser on topic Make "Submit" button appear only if people answer "Yes" for a Yes/No question
I have tried to write a script for such a case, although the Submit button is simply disabled, not hidden.
I would appreciate if you guys can check it out because I am not sure it is bugless.
The code is placed into a radio list type of question with 'yes' and 'no' answer choices, coded as A1 and A2.
Thanks in advance! A survey sample attached.
PS. Does anyone know why we no longer can select in which language the code is displayed on the forum? It is only gray now.
I would appreciate if you guys can check it out because I am not sure it is bugless.
The code is placed into a radio list type of question with 'yes' and 'no' answer choices, coded as A1 and A2.
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}'); // Initially disable the Next/Submit button $('#ls-button-submit').prop('disabled', 'true').addClass('ui-state-disabled'); // Listeners on Yes/No radios to toggle the Next/Submit button $('input:radio[value="A1"]', thisQuestion).click(function(){ $('#ls-button-submit').prop('disabled', '').removeClass('ui-state-disabled'); }); $('input:radio[value="A2"]', thisQuestion).click(function(){ $('#ls-button-submit').prop('disabled', 'true').addClass('ui-state-disabled'); }); }); </script>
Thanks in advance! A survey sample attached.
PS. Does anyone know why we no longer can select in which language the code is displayed on the forum? It is only gray now.
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Last edit: 5 years 1 week ago by tpartner. Reason: Added code language
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10098
- Thank you received: 3589
5 years 1 week ago #182945
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 Make "Submit" button appear only if people answer "Yes" for a Yes/No question
The script looks good.
You can still manually add a language to the code block - I have edited your post accordingly.
You can still manually add a language to the code block - I have edited your post accordingly.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- krosser
- Offline
- Elite Member
Less
More
- Posts: 222
- Thank you received: 10
5 years 1 week ago #182946
by krosser
Many thanks for checking it out! It is just I have had some strange behavior of conditioned questions not being displayed properly after adding this code. When the survey is active the conditions work, but when it is inactive, then they don't work in the preview.
What should be added to the block, for example, for JS?
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Replied by krosser on topic Make "Submit" button appear only if people answer "Yes" for a Yes/No question
tpartner wrote: The script looks good.
You can still manually add a language to the code block - I have edited your post accordingly.
Many thanks for checking it out! It is just I have had some strange behavior of conditioned questions not being displayed properly after adding this code. When the survey is active the conditions work, but when it is inactive, then they don't work in the preview.
What should be added to the block, for example, for JS?
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13597
- Thank you received: 2487
5 years 1 week ago #182947
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic Make "Submit" button appear only if people answer "Yes" for a Yes/No question
There are no submit button in preview, then the script broke when you try to update an attribute
Add this
just before // Identify this question
I don't understand why Expression Manager broke if there are error here … Maybe limesurvey core can do somthing here : EM javascript work with (some) broken JS in question text.
Add this
Code:
if(!$('#ls-button-submit').length != 1) { return; }
I don't understand why Expression Manager broke if there are error here … Maybe limesurvey core can do somthing here : EM javascript work with (some) broken JS in question text.
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
- krosser
- Offline
- Elite Member
Less
More
- Posts: 222
- Thank you received: 10
5 years 1 week ago #182948
by krosser
Perhaps I didn't add it in the right place, but it brakes the script.
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Replied by krosser on topic Make "Submit" button appear only if people answer "Yes" for a Yes/No question
DenisChenu wrote: There are no submit button in preview, then the script broke when you try to update an attribute
Add thisjust before // Identify this questionCode:if(!$('#ls-button-submit').length != 1) { return; }
I don't understand why Expression Manager broke if there are error here … Maybe limesurvey core can do somthing here : EM javascript work with (some) broken JS in question text.
Perhaps I didn't add it in the right place, but it brakes the script.
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { if(!$('#ls-button-submit').length != 1) { return; } // Identify this question var thisQuestion = $('#question{QID}'); // Initially disable the Next/Submit button $('#ls-button-submit').prop('disabled', 'true').addClass('ui-state-disabled'); // Listeners on Yes/No radios to toggle the Next/Submit button $('input:radio[value="A1"]', thisQuestion).click(function(){ $('#ls-button-submit').prop('disabled', '').removeClass('ui-state-disabled'); }); $('input:radio[value="A2"]', thisQuestion).click(function(){ $('#ls-button-submit').prop('disabled', 'true').addClass('ui-state-disabled'); }); }); </script>
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10098
- Thank you received: 3589
5 years 1 week ago #182949
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 Make "Submit" button appear only if people answer "Yes" for a Yes/No question
Try wrapping the whole thing in an if() statement that looks for the submit button:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { if($('#ls-button-submit').length > 0) { // Identify this question var thisQuestion = $('#question{QID}'); // Initially disable the Next/Submit button $('#ls-button-submit').prop('disabled', 'true').addClass('ui-state-disabled'); // Listeners on Yes/No radios to toggle the Next/Submit button $('input:radio[value="A1"]', thisQuestion).click(function(){ $('#ls-button-submit').prop('disabled', '').removeClass('ui-state-disabled'); }); $('input:radio[value="A2"]', thisQuestion).click(function(){ $('#ls-button-submit').prop('disabled', 'true').addClass('ui-state-disabled'); }); } }); </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: krosser
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13597
- Thank you received: 2487
5 years 1 week ago #182950
by DenisChenu
It's not ! it with …
Personnaly i prefer to quit when not needed than wrap inside a big if when needed. I think it's more clear
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic Make "Submit" button appear only if people answer "Yes" for a Yes/No question
Perhaps i made an error …krosser wrote: Perhaps I didn't add it in the right place, but it brakes the script.
It's not ! it with …
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { if($('#ls-button-submit').length != 1) { return; } // Identify this question var thisQuestion = $('#question{QID}'); // Initially disable the Next/Submit button $('#ls-button-submit').prop('disabled', 'true').addClass('ui-state-disabled'); // Listeners on Yes/No radios to toggle the Next/Submit button $('input:radio[value="A1"]', thisQuestion).click(function(){ $('#ls-button-submit').prop('disabled', '').removeClass('ui-state-disabled'); }); $('input:radio[value="A2"]', thisQuestion).click(function(){ $('#ls-button-submit').prop('disabled', 'true').addClass('ui-state-disabled'); }); }); </script>
Personnaly i prefer to quit when not needed than wrap inside a big if when needed. I think it's more clear
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: krosser
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10098
- Thank you received: 3589
5 years 1 week ago #182956
by tpartner
There is very little difference in execution resources between the two methods, although mine should be marginally quicker as the code inside the IF() statement is not executed.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Make "Submit" button appear only if people answer "Yes" for a Yes/No question
Yeah but I think that's a matter of personal preference.Personnaly i prefer to quit when not needed than wrap inside a big if when needed. I think it's more clear
There is very little difference in execution resources between the two methods, although mine should be marginally quicker as the code inside the IF() statement is not executed.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.