Welcome, Guest
Username: Password: Remember me

TOPIC: Using assignment operator to set a default value for a list type question

Using assignment operator to set a default value for a list type question 1 year 2 months ago #95660

  • ViliLe
  • ViliLe's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Thank you received: 1
  • Karma: 0
Hi All!

I've been using LimeSurvey since 2008 (and donated as well;), but this is the first time I need to ask a question on the forum. Shows how good a resource the manuals and forum discussions are :)

Here's what I'm trying to do: Respondents choose their year of birth form a dropdown list. I want to establish quotas for certain age groups (e.g. only one hundred 15-19-year-olds allowed). The problem is that the quota feature doesn't support this -- I can only establish quotas for individual years, not for ranges of years.

I'm trying to work around this by having a hidden list type variable called agegroup and using that as the basis for the quota. I'm trying to use the Expression Manager's assignment operator ( = ) to assign a value to agegroup based on the year of birth. But I'm not getting the assignment operator to work.

Sample code (placed in the question text field of a dummy question called agegroupcalc):
{if(intval(yearborn) > 1998, agegroup='a', if(intval(yearborn) > 1993, agegroup='b', if(intval(yearborn) > 1988, agegroup='c', if(intval(yearborn) > 1983, agegroup='d', agegroup='a'))))}
{agegroup}

Output (assuming yearborn equals 1990 and agegroupcalc is on the same page as agegroup):

c
a

In other words, the assignment operator doesn't seem to be working, or the variable agegroup forgets the assigned value immediately (and strangely defaults to 'a' even though no default is assigned and it's not a mandatory question). I've also tried assigning to yearborn.code instead of yearborn, but the result is the same. I've also played around with different question ordering.

Searching the forum, I've found that TMSWhite seems to be an expert on this topic and has answered a very similar query before:

www.limesurvey.org/en/forum/can-i-do-thi...to-previous-question

But the solution he attached is (no longer?) available.

I'm on LimeSurvey 2.00. Any help would be much appreciated!
The administrator has disabled public write access.

Using assignment operator to set a default value for a list type question 1 year 2 months ago #95664

  • Ben_V
  • Ben_V's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 1061
  • Thank you received: 234
  • Karma: 74
I can only establish quotas for individual years, not for ranges of years.

2 old posts to help you to change your mind ;) :

1. Calculate age in an Equation type question, using Date of Birth

2. How to create a calculated 'Age Ranges' question out of 'Age' numeric?
Benoît

goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
The administrator has disabled public write access.

Using assignment operator to set a default value for a list type question 1 year 2 months ago #95675

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6205
  • Thank you received: 788
  • Karma: 238
Hello,

To assign with some condition, you need to do like this.
Exemple assign question code ASSIGNED by "OK" or "NOK" according to QCODE is A1 or not.
{ASSIGNED=if(QCODE=="A1","OK","NOK")}

Because here, you assign 1st agegroup='a' and just after agegroup='b'. It's a bad issue with EM but very difficult to change it.

Denis
The administrator has disabled public write access.
The following user(s) said Thank You: ViliLe

Using assignment operator to set a default value for a list type question 1 year 2 months ago #95754

  • ViliLe
  • ViliLe's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Thank you received: 1
  • Karma: 0
Ben_V wrote:
I can only establish quotas for individual years, not for ranges of years.

2 old posts to help you to change your mind ;) :

1. Calculate age in an Equation type question, using Date of Birth

2. How to create a calculated 'Age Ranges' question out of 'Age' numeric?

Thanks, but those posts show how to calculate age groups into equation type questions. Quotas cannot be set on equation type questions.
The administrator has disabled public write access.

Using assignment operator to set a default value for a list type question 1 year 2 months ago #95755

  • ViliLe
  • ViliLe's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Thank you received: 1
  • Karma: 0
DenisChenu wrote:
To assign with some condition, you need to do like this.
Exemple assign question code ASSIGNED by "OK" or "NOK" according to QCODE is A1 or not.
{ASSIGNED=if(QCODE=="A1","OK","NOK")}

Because here, you assign 1st agegroup='a' and just after agegroup='b'. It's a bad issue with EM but very difficult to change it.

Thanks, this worked perfectly! So in case someone is interested, now my code is:
{agegroup = if(intval(yearborn) > 1998, 'a', if(intval(yearborn) > 1993, 'b', if(intval(yearborn) > 1988, 'c', if(intval(yearborn) > 1983, 'd', 'a'))))}

This code is placed in a hidden dummy question (agegroupcalc) on the same page as the yearborn question. The question "agegroup" is placed on the next page (the quota doesn't work if agegroupcalc and agegroup are on the same page).
The administrator has disabled public write access.

Using assignment operator to set a default value for a list type question 1 year 2 months ago #96317

  • ViliLe
  • ViliLe's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Thank you received: 1
  • Karma: 0
After further testing, I unfortunately have to report that this solution doesn't seem to work after all. In my Chrome it works at least most of the time, but in Safari I can't get it to work at all. I.e. I'm not able to change the default value of a radio list using EM code.

After spending about 12 hours trying to implement a "Select your year of birth" -> (calculate age group) -> (apply quota based on age group) system, I'm giving up and just going the unelegant way of simply asking users to enter both their year of birth as well as their age group :P
The administrator has disabled public write access.

Using assignment operator to set a default value for a list type question 1 year 2 months ago #96330

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6205
  • Thank you received: 788
  • Karma: 238
ViliLe wrote:
After further testing, I unfortunately have to report that this solution doesn't seem to work after all. In my Chrome it works at least most of the time, but in Safari I can't get it to work at all. I.e. I'm not able to change the default value of a radio list using EM code.
Sh .....

It must work on Safari as well as other navigator ..

You do the assignment in the same page or in another page (think it's best in another page) ?
Did you test with somethink more simple ?

Can you provide a little (most little you can survey showing the difference between Safaro and FF/Chrome ?

Did you know how to log javascript console on Safari (and then send us the result of the error log for Safari).

If you have all this one, think you can do a bug report.

Denis
The administrator has disabled public write access.

Using assignment operator to set a default value for a list type question 1 year 2 months ago #96336

  • ViliLe
  • ViliLe's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Thank you received: 1
  • Karma: 0
Thanks for your response.
DenisChenu wrote:
You do the assignment in the same page or in another page (think it's best in another page) ?

Yes, my dummy question with the assignment operation is on page 1 and the list question on page 2. If I put them on the same page, it doesn't work on either browser.
DenisChenu wrote:
Did you test with somethink more simple ?

Can you provide a little (most little you can survey showing the difference between Safaro and FF/Chrome ?

Did you know how to log javascript console on Safari (and then send us the result of the error log for Safari).

If you have all this one, think you can do a bug report.

These are good steps that you suggest, but unfortunately I had to give up on investigating this any further for now, because the survey needs to go live asap. If/when I have a free moment, I would like to do exactly what you suggest in the interest of solving this problem for the future.
The administrator has disabled public write access.
The following user(s) said Thank You: DenisChenu
Moderators: ITEd
Time to create page: 0.328 seconds
Donation Image