- Posts: 222
- Thank you received: 10
- Forum
- English support forums
- Can I do this with LimeSurvey?
- Make "Submit" button appear only if people answer "Yes" for a Yes/No question
Make "Submit" button appear only if people answer "Yes" for a Yes/No question
3 years 2 months 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 questionif(!$('#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.
<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.
3 years 2 months 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:
<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
-
- Away
- LimeSurvey Community Team
-
Less
More
- Posts: 15280
- Thank you received: 2733
3 years 2 months 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 …
<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.
3 years 2 months 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.