- Posts: 1
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Default Answers with question type : array (texts?)
- apalms
- Topic Author
- Offline
- New Member
Less
More
11 years 1 month ago #93850
by apalms
Default Answers with question type : array (texts?) was created by apalms
Hi all!
I am working with version 2.0, and am trying to figure out if it is possible to add default answers in the question type array texts.
The below is how my array will be constructed.
H01 H02 H03 H04
B01 DEFAULT XXX XXX XXX
B02 DEFAULT XXX XXX XXX
B03 DEFAULT XXX XXX XXX
Thank you!!
I am working with version 2.0, and am trying to figure out if it is possible to add default answers in the question type array texts.
The below is how my array will be constructed.
H01 H02 H03 H04
B01 DEFAULT XXX XXX XXX
B02 DEFAULT XXX XXX XXX
B03 DEFAULT XXX XXX XXX
Thank you!!
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
11 years 1 month ago - 11 years 1 month ago #93870
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Default Answers with question type : array (texts?)
There is no built-in setting for defaults in text arrays but you can do it with a little JavaScript.
Set up your survey to use JavaScript and add something like this to the question source.
Set up your survey to use JavaScript and add something like this to the question source.
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var defaultText = 'My default'; $('#question{QID} tr[id^="javatbd"]').each(function(i) { if($('input[type="text"]:eq(0)', this).val() == '') { $('input[type="text"]:eq(0)', this).val(defaultText) } }); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 11 years 1 month ago by tpartner.
The topic has been locked.
- sys_sby01
- Offline
- New Member
Less
More
- Posts: 10
- Thank you received: 0
11 years 1 month ago - 11 years 1 month ago #93883
by sys_sby01
Replied by sys_sby01 on topic Default Answers with question type : array (texts?)
Hello tpartner,
I need hep and information,
where is the file located for reference function/class:
1. ('#question{QID} tr[id^="javatbd"]')
2. ('input[type="text"]:eq(0)
Hoping i can to use javaScript for others type question
Thank you
Regards
sys_sby
I need hep and information,
where is the file located for reference function/class:
1. ('#question{QID} tr[id^="javatbd"]')
2. ('input[type="text"]:eq(0)
Hoping i can to use javaScript for others type question
Thank you
Regards
sys_sby
Last edit: 11 years 1 month ago by sys_sby01.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
11 years 1 month ago #93904
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Default Answers with question type : array (texts?)
I'm not sure I understand the question.
1. ('#question{QID} tr[id^="javatbd"]') - This refers to the array rows
2. ('input[type="text"]:eq(0) - This refers to the first text input in the rows
The easiest way to discover element classes and other attributes is with developer tools like Firebug for Firefox:
1. ('#question{QID} tr[id^="javatbd"]') - This refers to the array rows
2. ('input[type="text"]:eq(0) - This refers to the first text input in the rows
The easiest way to discover element classes and other attributes is with developer tools like Firebug for Firefox:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.
- sys_sby01
- Offline
- New Member
Less
More
- Posts: 10
- Thank you received: 0
11 years 1 month ago #93911
by sys_sby01
Replied by sys_sby01 on topic Default Answers with question type : array (texts?)
Hello Tony,
I mean that's it
Thank you very much
Regards
sys_sby
I mean that's it
Thank you very much
Regards
sys_sby
The topic has been locked.
- Freija_K
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
5 years 1 week ago #183511
by Freija_K
Replied by Freija_K on topic Default Answers with question type : array (texts?)
Hey I used this script and it works but only for the first subquestion. How can I make sure that the default answer applies to all subquestions?
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
5 years 1 week ago #183512
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Default Answers with question type : array (texts?)
This will place the default text into all of the inputs in that question:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var defaultText = 'My default'; $('#question{QID} tr[id^="javatbd"] input:text').each(function(i) { if($(this).val() == '') { $(this).val(defaultText) } }); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: cdorin
The topic has been locked.
- Freija_K
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
5 years 1 week ago #183514
by Freija_K
Replied by Freija_K on topic Default Answers with question type : array (texts?)
Thank you! this works perfectly!
kind regards
Freija
kind regards
Freija
The topic has been locked.