Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Undifiend variable

  • Pareyzi
  • Pareyzi's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 1 month ago - 2 years 1 month ago #225101 by Pareyzi
Undifiend variable was created by Pareyzi
Please help us help you and fill where relevant:Your LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]Own server or LimeSurvey hosting:Survey theme/template:==================(Write here your question/remark)
Hi, it would be great if someone can help me with this issue.I have wrote a code and it was working in my previous account (Capture attachement is the result of coding) and the version of my previous account was 5.2.13. I have to transfer my all work to university account and the version is 3.28.0. when I am importing my previous code in new account, it is not working. I even tried to just copy paste the code, but after saving the code it is not working right. This is the code:

<style type="text/css">.big-radio {
    width: 17px !important;
      height: 17px !important;
  }
  .clickable-span:hover {
    cursor: pointer;
    text-decoration: underline;
  }
</style>
<script type="text/javascript" charset="utf-8">
    var checkClosest = function(elem) {
      elem.firstElementChild.click();
    };
 
      $(document).on('ready pjax:scriptcomplete', function(){
        var thisQuestion = $('#question{QID}');
      
        // Insert radios
        // Zapisuje się w bazie: [...value=] natomiast wyświetlane w pytaniu jest to, co stoi zaraz za [...id="radio-X" />]
        if(!document.querySelector(".inserted-radio")){
            $('.answer-item.answer_cell_X001', thisQuestion).addClass('with-select').append(
              '<div style="text-align: left" class="list-question-select">\
                <span onclick="checkClosest(this)">\
                    <input value="--N/A" class="inserted-radio" type="radio" name="radio_" id="radio-1" /> --N/A     </span><br />\
                <span onclick="checkClosest(this)">\
                    <input value="1. Always" class="inserted-radio" type="radio" name="radio_" id="radio-1" /> 1. Always     </span><br />\
                <span onclick="checkClosest(this)">\
                    <input value="2. Often" class="inserted-radio" type="radio" name="radio_" id="radio-2" /> 2. Often     </span><br />\
                <span onclick="checkClosest(this)">\
                    <input value="3. Sometimes" class="inserted-radio" type="radio" name="radio_" id="radio-3" /> 3. Sometimes  </span> <br /> \
                <span onclick="checkClosest(this)">\
                    <input value="4. Never" class="inserted-radio" type="radio" name="radio_" id="radio-1" /> 4. Never     </span><br />\
                <span onclick="checkClosest(this)">\
              </div>'
            );
            $('.answer-item.answer_cell_X002', thisQuestion).addClass('with-select').append(
              '<div style="text-align: left" class="list-question-select">\
                <span onclick="checkClosest(this)">\
                    <input value="--N/A" class="inserted-radio" type="radio" name="radio_" id="radio-1" /> --N/A     </span><br />\
                <span onclick="checkClosest(this)">\
                    <input value="1. Chats/texts on virtual platforms (Informal communication)" class="inserted-radio" type="radio" name="radio_" id="radio-1" /> 1. Chats/texts on virtual platforms (informal communication)    </span><br />\
                <span onclick="checkClosest(this)">\
                    <input value="2. Emails" class="inserted-radio" type="radio" name="radio_" id="radio-2" /> 2. Emails     </span><br />\
                <span onclick="checkClosest(this)">\
                    <input value="3. Phone calls" class="inserted-radio" type="radio" name="radio_" id="radio-3" /> 3. Phone calls   </span><br />\
                <span onclick="checkClosest(this)">\
                    <input value="4. Meetings (in-person or virtual)" class="inserted-radio" type="radio" name="radio_" id="radio-3" /> 4. Meetings (in-person or vitual)   </span><br />\
                </div>'
            );
            $('.answer-item.answer_cell_X003', thisQuestion).addClass('with-select').append(
              '<div style="text-align: left" class="list-question-select">\
                <span onclick="checkClosest(this)">\
                    <input value="--N/A" class="inserted-radio" type="radio" name="radio_" id="radio-1" /> --N/A </span><br />\
                <span onclick="checkClosest(this)">\
                    <input value="1. Always" class="inserted-radio" type="radio" name="radio_" id="radio-1" /> 1. Always </span><br />\
                <span onclick="checkClosest(this)">\
                    <input value="2. Sometimes"        class="inserted-radio" type="radio" name="radio_" id="radio-2" /> 2. Sometimes        </span><br />\
                <span onclick="checkClosest(this)">\
                    <input value="3. Often"     class="inserted-radio" type="radio" name="radio_" id="radio-3" /> 3. Often     </span><br />\
                <span onclick="checkClosest(this)">\
                    <input value="4. Never"        class="inserted-radio" type="radio" name="radio_" id="radio-4" /> 4. Never        </span><br />\
                <span onclick="checkClosest(this)">\
              </div>'
               );
            $('.answer-item.answer_cell_X004', thisQuestion).addClass('with-select').append(
              '<div style="text-align: left" class="list-question-select">\
                <span onclick="checkClosest(this)">\
                    <input value="--N/A" class="inserted-radio" type="radio" name="radio_" id="radio-1" /> --N/A </span><br />\
                <span onclick="checkClosest(this)">\
                    <input value="1. Always" class="inserted-radio" type="radio" name="radio_" id="radio-1" /> 1. Always </span><br />\
                <span onclick="checkClosest(this)">\
                    <input value="2. Sometimes"        class="inserted-radio" type="radio" name="radio_" id="radio-2" /> 2. Sometimes        </span><br />\
                <span onclick="checkClosest(this)">\
                    <input value="3. Often"     class="inserted-radio" type="radio" name="radio_" id="radio-3" /> 3. Often     </span><br />\
                <span onclick="checkClosest(this)">\
                    <input value="4. Never"        class="inserted-radio" type="radio" name="radio_" id="radio-4" /> 4. Never        </span><br />\
                <span onclick="checkClosest(this)">\
              </div>'
            );
        }
        document.querySelectorAll("input[id^='answer']").forEach( function(inputElem){
          var currID = inputElem.id.substr(6);
          inputElem.parentElement.querySelector("div.list-question-select").querySelectorAll('input').forEach( function(radioNeedsName){
            radioNeedsName.name += currID;
            // Łapiemy zmiany i uzupełniamy oryginalny element
            radioNeedsName.addEventListener("change", function(){
              inputElem.value = event.target.value;
            })
          })
        });
      
        // Clean-up styles
        $('input.inserted-radio').addClass('big-radio');
        $('.list-question-select').find('span').addClass('clickable-span')
        $('.with-select input:text', thisQuestion).css({
            'position': 'absolute',
            'left': '-9999em'
        });
    });
</script><script>
     // Zmiana atrybutu name radiosów tak, aby działała wyłączność per subpytanie (Y)
    function applyCustomRadios() {
      document.querySelectorAll("input[id^='answer']").forEach( function(inputElem){
        var currID = inputElem.id.substr(6);
        inputElem.parentElement.querySelector("div.list-question-select").querySelectorAll('input').forEach( function(radioNeedsName){
          radioNeedsName.name += currID;
          // Łapiemy zmiany i uzupełniamy oryginalny element
          radioNeedsName.addEventListener("change", function(){
            inputElem.value = event.target.value;
          })
        });
        inputElem.parentElement.querySelector("div.list-question-select").querySelectorAll('label').forEach( function(radioNeedsName){
          radioNeedsName.name += currID;
          // Łapiemy zmiany i uzupełniamy oryginalny element
          radioNeedsName.addEventListener("change", function(){
            inputElem.value = event.target.value;
          })
        })
      });
    }

      document.addEventListener('ready pjax:scriptcomplete', applyCustomRadios)
      document.addEventListener('pjax:scriptcomplete', applyCustomRadios)
</script>


But after saving it in new account, it is changing to :

{QID}'); // Insert radios // Zapisuje się w bazie: [...value=] natomiast wyświetlane w pytaniu jest to, co stoi zaraz za [...id="radio-X" />] if(!document.querySelector(".inserted-radio")){ $('.answer-item.answer_cell_X001', thisQuestion).addClass('with-select').append( '
<div class="list-question-select" style="text-align:left;">\ <span>\ --N/A </span><br />\ <span>\ 1. Always </span><br />\ <span>\ 2. Often </span><br />\ <span>\ 3. Sometimes </span><br />\ <span>\ 4. Never </span><br />\ <span>\ </span></div>
' ); $('.answer-item.answer_cell_X002', thisQuestion).addClass('with-select').append( '

<div class="list-question-select" style="text-align:left;">\ <span>\ --N/A </span><br />\ <span>\ 1. Chats/texts on virtual platforms (informal communication) </span><br />\ <span>\ 2. Emails </span><br />\ <span>\ 3. Phone calls </span><br />\ <span>\ 4. Meetings (in-person or vitual) </span><br />\</div>
' ); $('.answer-item.answer_cell_X003', thisQuestion).addClass('with-select').append( '

<div class="list-question-select" style="text-align:left;">\ <span>\ --N/A </span><br />\ <span>\ 1. Always </span><br />\ <span>\ 2. Sometimes </span><br />\ <span>\ 3. Often </span><br />\ <span>\ 4. Never </span><br />\ <span>\ </span></div>
' ); $('.answer-item.answer_cell_X004', thisQuestion).addClass('with-select').append( '

<div class="list-question-select" style="text-align:left;">\ <span>\ --N/A </span><br />\ <span>\ 1. Always </span><br />\ <span>\ 2. Sometimes </span><br />\ <span>\ 3. Often </span><br />\ <span>\ 4. Never </span><br />\ <span>\ </span></div>
' ); } document.querySelectorAll("input[id^='answer']").forEach( function(inputElem){ var currID = inputElem.id.substr(6); inputElem.parentElement.querySelector("div.list-question-select").querySelectorAll('input').forEach( function(radioNeedsName){ radioNeedsName.name += currID; // Łapiemy zmiany i uzupełniamy oryginalny element radioNeedsName.addEventListener("change", function(){ inputElem.value = event.target.value; }) }) }); // Clean-up styles $('input.inserted-radio').addClass('big-radio'); $('.list-question-select').find('span').addClass('clickable-span') $('.with-select input:text', thisQuestion).css({ 'position': 'absolute', 'left': '-9999em' }); });
Last edit: 2 years 1 month ago by Pareyzi.

Please Log in to join the conversation.

  • Pareyzi
  • Pareyzi's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 1 month ago #225102 by Pareyzi
Replied by Pareyzi on topic Undifiend variable
Attached files:

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 1 month ago #225107 by tpartner
Replied by tpartner on topic Undifiend variable
Do you have permissions to insert JavaScript in the 3.x installation?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • Pareyzi
  • Pareyzi's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 1 month ago #225113 by Pareyzi
Replied by Pareyzi on topic Undifiend variable
What do you mean by 3.x? It would be great if you please let me know what kind of permissions should I have? Because it is university account and I have to ask my supervisor to give the permission. Thanks.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 1 month ago - 2 years 1 month ago #225121 by tpartner
Replied by tpartner on topic Undifiend variable

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 2 years 1 month ago by tpartner.
The following user(s) said Thank You: Pareyzi

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose