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

TOPIC: How can I set default values?

How can I set default values? 1 year 3 months ago #95315

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?
The administrator has disabled public write access.

How can I set default values? 1 year 3 months ago #95331

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4118
  • Thank you received: 760
  • Karma: 346
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.
The administrator has disabled public write access.
The following user(s) said Thank You: frank4wheels

How can I set default values? 1 year 3 months ago #95372

(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.
The administrator has disabled public write access.

How can I set default values? 1 year 3 months ago #95389

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4118
  • Thank you received: 760
  • Karma: 346
...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.
The administrator has disabled public write access.

How can I set default values? 1 year 3 months ago #95395

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.
Attachments:
Last Edit: 1 year 3 months ago by frank4wheels.
The administrator has disabled public write access.

How can I set default values? 1 year 3 months ago #95397

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.
Attachments:
The administrator has disabled public write access.

How can I set default values? 11 months 3 weeks ago #99382

  • papacico
  • papacico's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 20
  • Karma: 0
hello frank4wheels did you solved this problem already?
I have the same problem as well

thank you in advance

ciao
The administrator has disabled public write access.

How can I set default values? 11 months 3 weeks ago #99386

No, I didn't; I gave up.
I am sorry.
The administrator has disabled public write access.

How can I set default values? 11 months 3 weeks ago #99432

  • trivender
  • trivender's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 142
  • Thank you received: 6
  • Karma: 6
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."
The administrator has disabled public write access.

How can I set default values? 11 months 3 weeks ago #99450

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".
Attachments:
Last Edit: 11 months 3 weeks ago by frank4wheels. Reason: Add
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.159 seconds
Donation Image