Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Using Expressions Manager to auto-insert survey, group and question ID in js

Re: Using Expressions Manager to auto-insert survey, group and question ID in js 2 years 7 months ago #75668

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4271
  • Thank you received: 805
  • Karma: 369
If you have defined a variable questionID with the code above you can do something like:
<script>
    $(document).ready(function() {
        $('#question'+questionID+'').hide();
    });
</script>
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Using Expressions Manager to auto-insert survey, group and question ID in js 2 years 7 months ago #75672

Maybe I am placing the code in the wrong area but the javascript seems to be having no impact. I've placed the previous code in the question edit box and the below code in the help field edit box:

<script>
$(document).ready(function() {
$('#questiongroupID'+questionID2+'').hide();
});
</script>

I am using the same reference for questionID (questiongroupID) that I used in the question editor box and questionID2 is also a reference from the question edit box code. However, I have tried several variations and the only thing that seems to work is code that includes the specific question number - which then works seamlessly. Am I doing something wrong? Do I need to combine the two scripts? Any advice would be helpful.
The administrator has disabled public write access.

Re: Using Expressions Manager to auto-insert survey, group and question ID in js 2 years 7 months ago #75676

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4271
  • Thank you received: 805
  • Karma: 369
Use my code as an example.

This: #questiongroupID

Should just be: #question
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Using Expressions Manager to auto-insert survey, group and question ID in js 2 years 7 months ago #75680

Thanks for your help with this. I should have started the previous post by saying that I started with the code that you provided but it had no effect. I believe that the script is not capturing the question id. What I posted was my third attempt at restructing the script to try to make it work with no success. Could this be a placement issue as far as where the script is located? Should I try inserting it into one of the subquestion fields instead of the Help area?
The administrator has disabled public write access.

Re: Using Expressions Manager to auto-insert survey, group and question ID in js 2 years 7 months ago #75681

You're awesome! I got it to work. I needed to insert the line of code into the larger code block that appeared earlier in the page. Since the earlier code block already establishes the questionID, it worked perfectly. There is one last component that I need help with. I have a series of datepickers that populates a series of fields in an array question. As with the previous, I need to alter the javascript to identify the field name so that the survey can be copied without the need for direct intervention. Here is that code:

<script type="text/javascript" charset="utf-8">

$(document).ready(function() {
var qID = 3173;

// Add column-specific classes to array cells
$('#question'+qID+' table.question tr').each(function(i, el){
$('> *', this).each(function(i, el){
$(el).addClass('col-'+i);
});
});

// Apply datepicker to text inputs
$('#question'+qID+' .col-1 input[type="text"], #question'+qID+' .col-2 input[type="text"]').datepicker({
dateFormat: 'mm/dd/yy'
});

});

</script>

Can you provide quideance on where and how the code should be altered so that the question ID is handled by the javascript?

Thanks in advance for your help.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.106 seconds
Donation Image