Bienvenue, Invité
Nom d'utilisateur : Mot de passe : Se souvenir de moi
  • Page :
  • 1
  • 2

SUJET : How can I set default values?

How can I set default values? il y a 11 mois 3 semaines #95315

  • frank4wheels
  • Portrait de frank4wheels
  • Hors ligne
  • Fresh Lemon
  • Messages : 16
  • Karma: 0
I was able to set default value for question type text, but I did'd find information for other question type (gender,...).

Can someone help me or tell me where can I get information?
L'administrateur a désactivé l'accès en écriture pour le public.

How can I set default values? il y a 11 mois 3 semaines #95331

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 3813
  • Remerciements reçus 683
  • Karma: 328
I'm not sure why that question type doesn't have a default option but you can do it with a little JavaScript.

For example, in a radio question, if you want the first answer to be default, add this to the question source:
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		var qID = {QID};
 
		if($('#question'+qID+' input.radio:checked').length == 0) {
			$('#question'+qID+' input.radio:eq(0)').click();
		}
	});
</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.
L'administrateur a désactivé l'accès en écriture pour le public.
Cet utilisateur a été remercié pour son message par: frank4wheels

How can I set default values? il y a 11 mois 3 semaines #95372

  • frank4wheels
  • Portrait de frank4wheels
  • Hors ligne
  • Fresh Lemon
  • Messages : 16
  • Karma: 0
(I am sorry for my bad english :sick: ).

I thank you for your answer, but where I have to put the code?

My problem is more complex:
It is first time I use Limesurvey.
I use it for a non-profit organization.
People that will use it could be an associate or a contact (we will invite them and we have a lot of information about it: first name, last name, email address, date of birth, gender, home city,...) but can be also people that get the link on an website (ag a social network).

If we have information about him/her, I would like put it automatically by default.
So I thought:
- to define additional parameters in Central participants database and load First Name - Last Name - Email and values of parameters from a CSV file
- put TOKEN as default value (for each parameter).
In this way, associates and contacts have not to input some values.

When I tried, my first problem was that Gender has non default box.
An other question is how can I get that questions are shown only if there isn't a value (in the case of users that are not associates or contacts)?

I hope that all is clear...

I will appreciate your help.
L'administrateur a désactivé l'accès en écriture pour le public.

How can I set default values? il y a 11 mois 2 semaines #95389

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 3813
  • Remerciements reçus 683
  • Karma: 328
...where I have to put the code?
In the question source. See - manual.limesurvey.org/Workarounds:_Manip....29_in_LimeSurvey.3F.


For the gender question:
If you are using "attribute_1" for the gender token value and those values are "F" or "M", you can use this script in the source of that question. (I think the comments in the script adequately describe what it will do):
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		// Identify this question
		var qID = {QID};
 
		// Get the gender from the token
		var gender = {TOKEN:ATTRIBUTE_1};
 
		// If there is a known gender value...
		if(gender != '') {
 
			// Click the appropriate radio
			$('#question'+qID+' input.radio[value="'+gender+'"]').click();
			// Hide the question
			$('#question'+qID+'').hide();
		}
	});
</script>


For a text question like "First name";
If you are using "attribute_2" for the "First name" token value", you can use this script in the source of that question. (I think the comments in the script adequately describe what it will do):
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		// Identify this question
		var qID = {QID};
 
		// Get the first name from the token
		var firstName = {TOKEN:ATTRIBUTE_2};
 
		// If there is a known first name value...
		if(firstName != '') {
 
			// Load the first name into the text input
			$('#question'+qID+' input[type="text"]').val(firstName);
			// Hide the question
			$('#question'+qID+'').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.
L'administrateur a désactivé l'accès en écriture pour le public.

How can I set default values? il y a 11 mois 2 semaines #95395

  • frank4wheels
  • Portrait de frank4wheels
  • Hors ligne
  • Fresh Lemon
  • Messages : 16
  • Karma: 0
I am sorry, but while you post I was writing the following my mew post post.

I will read your suggestions.
Thanks!

Can someone help me?
Please, explain me or where I can read "how".

I do not understand how
1- put default values
2- not show question when there is a default value (in same cases)
3- get answer read-only when there is a default value (in same cases)

I used Attributes (picture 1) to assign values.
Values are correctly load (picture 2).
I assigned default values
{TOKEN:LASTNAME} --> OK :laugh:
...
{TOKEN:Data_Nascita} (date of birth) --> Does not work :(
{TOKEN:EMAIL} --> OK :laugh:
{TOKEN:Telefono_fisso} (phone number) --> Does not work :(
The box displays
"<span style='background-color: #eee8aa;'><span title='Variabile non definita' style='border-style: solid; border-width: 2px; border-color: red;'><span title='Variabile non definita' style='color: red; font-weight: bold'>TOKEN:Telefono_fisso</span></span></span>"

I don't know
- how set default value to Gender
- how set default value to answers other than text; eg:
Stato_familiare - List (radio): Married/Not married
Have I put code into the box "Relevance equation"?

Help me, please.
Pièces jointes :
Dernière édition: il y a 11 mois 2 semaines par frank4wheels.
L'administrateur a désactivé l'accès en écriture pour le public.

How can I set default values? il y a 11 mois 2 semaines #95397

  • frank4wheels
  • Portrait de frank4wheels
  • Hors ligne
  • Fresh Lemon
  • Messages : 16
  • Karma: 0
I'm sorry, but it do not work (see attached).

I tried the code
<script type="text/javascript" charset="utf-8">
alert("Test!");
</script>

It works.
Pièces jointes :
L'administrateur a désactivé l'accès en écriture pour le public.

How can I set default values? il y a 7 mois 2 semaines #99382

  • papacico
  • Portrait de papacico
  • Hors ligne
  • Junior Lime
  • Messages : 20
  • Karma: 0
hello frank4wheels did you solved this problem already?
I have the same problem as well

thank you in advance

ciao
L'administrateur a désactivé l'accès en écriture pour le public.

How can I set default values? il y a 7 mois 2 semaines #99386

  • frank4wheels
  • Portrait de frank4wheels
  • Hors ligne
  • Fresh Lemon
  • Messages : 16
  • Karma: 0
No, I didn't; I gave up.
I am sorry.
L'administrateur a désactivé l'accès en écriture pour le public.

How can I set default values? il y a 7 mois 2 semaines #99432

  • trivender
  • Portrait de trivender
  • Hors ligne
  • Expert Lime
  • Messages : 117
  • Remerciements reçus 3
  • Karma: 4
Add attribute in token table and then use equation type question to auto-populate values anywhere later in survey.
Use something like {qid=TOKEN:ATTRIBUTE_1.NAOK} in equation question.Here qid is the question ID of the question where you want to auto-populate.
Trivender Singh
Survey Designer and Programmer
"I always suggest to have a group by group display layout and create a seprate group for each question. This will be extra work but you will get flexiblity to create your question by using more than more lime survey question types."
L'administrateur a désactivé l'accès en écriture pour le public.

How can I set default values? il y a 7 mois 2 semaines #99450

  • frank4wheels
  • Portrait de frank4wheels
  • Hors ligne
  • Fresh Lemon
  • Messages : 16
  • Karma: 0
Please, can you give me more information?

I have the table in attach 1; but I get the error in 2 if I use as in 3.


----
Error in 2 is "Undefined variable".
Pièces jointes :
Dernière édition: il y a 7 mois 2 semaines par frank4wheels. Raison: Add
L'administrateur a désactivé l'accès en écriture pour le public.
  • Page :
  • 1
  • 2
Modérateurs: ITEd
Temps de génération de la page : 0.169 secondes
Donation Image