Bienvenue, Invité
Nom d'utilisateur : Mot de passe : Se souvenir de moi

SUJET : 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 il y a 1 an 4 mois #95660

  • ViliLe
  • Portrait de ViliLe
  • Hors ligne
  • Fresh Lemon
  • Messages : 7
  • Remerciements reçus 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!
L'administrateur a désactivé l'accès en écriture pour le public.

Using assignment operator to set a default value for a list type question il y a 1 an 4 mois #95664

  • Ben_V
  • Portrait de Ben_V
  • Hors ligne
  • Platinum Lime
  • Messages : 1081
  • Remerciements reçus 240
  • Karma: 76
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...
L'administrateur a désactivé l'accès en écriture pour le public.

Using assignment operator to set a default value for a list type question il y a 1 an 4 mois #95675

  • DenisChenu
  • Portrait de DenisChenu
  • Hors ligne
  • Moderator Lime
  • Messages : 6334
  • Remerciements reçus 818
  • Karma: 243
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
L'administrateur a désactivé l'accès en écriture pour le public.
Cet utilisateur a été remercié pour son message par: ViliLe

Using assignment operator to set a default value for a list type question il y a 1 an 4 mois #95754

  • ViliLe
  • Portrait de ViliLe
  • Hors ligne
  • Fresh Lemon
  • Messages : 7
  • Remerciements reçus 1
  • Karma: 0
Ben_V écrit:
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.
L'administrateur a désactivé l'accès en écriture pour le public.

Using assignment operator to set a default value for a list type question il y a 1 an 4 mois #95755

  • ViliLe
  • Portrait de ViliLe
  • Hors ligne
  • Fresh Lemon
  • Messages : 7
  • Remerciements reçus 1
  • Karma: 0
DenisChenu écrit:
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).
L'administrateur a désactivé l'accès en écriture pour le public.

Using assignment operator to set a default value for a list type question il y a 1 an 3 mois #96317

  • ViliLe
  • Portrait de ViliLe
  • Hors ligne
  • Fresh Lemon
  • Messages : 7
  • Remerciements reçus 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
L'administrateur a désactivé l'accès en écriture pour le public.

Using assignment operator to set a default value for a list type question il y a 1 an 3 mois #96330

  • DenisChenu
  • Portrait de DenisChenu
  • Hors ligne
  • Moderator Lime
  • Messages : 6334
  • Remerciements reçus 818
  • Karma: 243
ViliLe écrit:
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
L'administrateur a désactivé l'accès en écriture pour le public.

Using assignment operator to set a default value for a list type question il y a 1 an 3 mois #96336

  • ViliLe
  • Portrait de ViliLe
  • Hors ligne
  • Fresh Lemon
  • Messages : 7
  • Remerciements reçus 1
  • Karma: 0
Thanks for your response.
DenisChenu écrit:
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 écrit:
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.
L'administrateur a désactivé l'accès en écriture pour le public.
Cet utilisateur a été remercié pour son message par: DenisChenu
Modérateurs: ITEd
Temps de génération de la page : 0.345 secondes
Donation Image