- Posts: 10244
- Thank you received: 3644
Ask the community, share ideas, and connect with other LimeSurvey users!
<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>
tpartner wrote: The script looks good.
You can still manually add a language to the code block - I have edited your post accordingly.
if(!$('#ls-button-submit').length != 1) { return; }
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.
<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>
<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>
Perhaps i made an error …krosser wrote: 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>
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