Welcome to the LimeSurvey Community Forum

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

hide question if prefilled

  • andrewz
  • andrewz's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 6 months ago #99927 by andrewz
hide question if prefilled was created by andrewz
I prefill one answer using a URL like this

www.example/index.php/survey/index/sid/7...712544X99X2152=12345

Then I set the "always hide" option. Most of the time, this works, but sometimes the parameters are missing, so the answer is blank.

When it is blank, I want to unhide the question. I tried using a relevance equation of !is_empty(foo), but this seems to always hide the question and break recording of the answer in both cases.

Version 2.00+ Build 130913
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 5 months ago #99936 by tpartner
Replied by tpartner on topic hide question if prefilled
I don't think you want to use relevance because the question should always be relevant, whether pre-populated or not.

Assuming it is a short-text question, try not using the "always hide" option, set up your survey to use JavaScript and add this to the question source:
Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function() {
    if($('#question{QID} input.text').val() == '') {
      $('#question{QID}.hide();
    }
  });  
</script>


Of course, this will also hide the question if a respondent answers it, moves on in the survey and then returns to the group later.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 5 months ago #99947 by DenisChenu
Replied by DenisChenu on topic hide question if prefilled
Hi,

Think i use 2 question.
First with hide settings prefilled by URL
Second : is_empty(FIRST)

ANd maybe a 2rd equation question type:
{FIRST.NAOK}{SECOND.NAOK}

Denis

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 topic has been locked.
  • andrewz
  • andrewz's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 5 months ago #99990 by andrewz
Replied by andrewz on topic hide question if prefilled
Denis, this sounds like what I came up with.

I added a second question which is irrelevant when the first question is not empty.
The topic has been locked.
More
10 years 2 months ago - 10 years 2 months ago #102944 by dweisser
Replied by dweisser on topic hide question if prefilled
I would like to hide the question if a textarea has been filled.

I'm using a question with a timer. It is the only question in the category.
I thought I had this working...
Code:
<script type="text/javascript" charset="utf-8">  
$(document).ready(function() {
  if($('#answer724821X200X1391').length > 0) {
      $('#question1391').hide();
alert($('#answer724821X200X1391').attr('value'));
  }
});
</script>

But it hides the question whether there is any text in the textarea or not. Any thoughts would be most appreciated. Thanks for maintaining such a great resource.
David
Last edit: 10 years 2 months ago by dweisser.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 2 months ago #102945 by tpartner
Replied by tpartner on topic hide question if prefilled
Try:
Code:
if($('#answer724821X200X1391').val() != '') {

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
10 years 2 months ago #102964 by dweisser
Replied by dweisser on topic hide question if prefilled
That did the trick.

You know, I was trying that at one point, but I was trying to extend the if statement to handle a Default Answer.
So:
Code:
<script type="text/javascript" charset="utf-8">  
$(document).ready(function() {
if(($('#answer724821X200X1391').val() != '') or ($('#answer724821X200X1391').val() != 'Enter your response here.')) {
      $('#question1391').hide();
//alert($('#answer724821X200X1391').attr('value'));
  }
});
</script>

But, it didn't work. I just got rid of the Default answer and all is well.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 2 months ago #102973 by tpartner
Replied by tpartner on topic hide question if prefilled
For a default answer in a text question, try:

Code:
if($('#answer724821X200X1391').val() != '' &amp;&amp; $('#answer724821X200X1391').val() != 'Enter your response here.') {

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
8 years 4 months ago - 8 years 4 months ago #127834 by AGK925
Replied by AGK925 on topic hide question if prefilled

tpartner wrote: I don't think you want to use relevance because the question should always be relevant, whether pre-populated or not.

Assuming it is a short-text question, try not using the "always hide" option, set up your survey to use JavaScript and add this to the question source:

Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function() {
    if($('#question{QID} input.text').val() == '') {
      $('#question{QID}.hide();
    }
  });  
</script>


Of course, this will also hide the question if a respondent answers it, moves on in the survey and then returns to the group later.


Is there documentation about how to do this for list or other non text questions? I would like to hide a question once it is answered. Thanks.
Last edit: 8 years 4 months ago by AGK925.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose