How to set a field to (condtionally) be disabled or readonly
Here's a trick to disable a question's input fields based on the evaluation of another question.

In the sample below, we have a question with the question code DisableMe (which has the value of Y or N). We assign the response value of that question code to the JavaScript lockit. We then check to see if lockit is equals Y or No. If Y, then we set our target question to be readonly.

IMPORTANT: The field want to disable is answer283991X3X13 : and this is actually comprised of 3 values, separated by an "X". The first digits are the surveyID, the next set of digits is the GroupID of the question, and the last digits are the QuestionID.

You can find the GroupID using the "List question groups" sidebar menu option, and the QuestionID using the "List Questions" sidebar menu option.

Here's the script - use the Source button in your question editor, and put this (modified based on details above), below your question text:


<script type="text/javascript" charset="utf-8">
    $(document).on('ready pjax:complete',function() {
         var lockit = '{DisableMe.NAOK}';
         if (lockit == 'Y')  {
               $("#answer283991X3X13").prop('readonly', true);
        } else {
               $("#answer283991X3X13").prop('readonly', false);
        }
    }
);
</script>

If you don't want to use a condition, and just want to diasble a field, you can use:

<span><script type="text/javascript" charset="utf-8">
    $(document).on('ready pjax:complete',function() {
                        $("#answer283991X3X13").prop('readonly', true);
    }
);
</script>

We greatly appreciate your feedback.




Powered by LiveZilla Helpdesk