Home
LimeSurvey Forums
Welcome, Guest
Please Login or Register.    Lost Password?
Re:[done] entering the survey answer automatically (1 viewing) (1) Guest
Go to bottom Favoured: 0
TOPIC: Re:[done] entering the survey answer automatically
#16527
Mark B (User)
Fresh Lemon
Posts: 5
graphgraph
User Offline Click here to see the profile of this user
[done] entering the survey answer automatically 2 Months, 2 Weeks ago Karma: 0  
I'm using LimeSurvey 1.70+

What I would like to do is use code to enter the answer to questions. For example,

<script type="text/javascript"><br />
95716X111X1036 = "Try 4";
// end hiding code --><br />
</script><br />

Is there a way that you can program the answer to a question? I've tried many minor variations to the above and none have worked to alther the answer to the question.

If this is possible I plan on using it for stated preference surveys. These surveys offer users choices (say shampoo X and Y) with different attributes (say price and size). However, respondents do not all get the same price and size - the attributes are randomized. The randomization is easy enough to do with JavaScript. My problem is I can't save the random price and size data that would be shown to respondents. If I could "force" the answers to unused questions to equal the price and size then I could save the price and size data along with the rest of the survey.
 
Logged Logged  
 
Last Edit: 2008/07/23 10:10 By Mazi.
  The administrator has disabled public write access.
#16536
jcleeland (Admin)
Moderator Lime
Posts: 240
graphgraph
User Online Now Click here to see the profile of this user
Re:entering the survey answer automatically 2 Months, 2 Weeks ago Karma: 6  
Have a look at the demo of the page, and view the source. Find the input form element with the SGQA code for the question you are answering, and you'll find it has an id as well.

Then the javascript could be:

<script type='text/javascript'>
document.getElementById('answer95716X111X1036'.value = 'Try 4';
</script>


I just gave this a try, and it does work. The only thing to note is that the javascript has to be run _after_ the input field has loaded.

So if you're doing this on a question-by-question basis, it worked for me when I loaded the javascript code in the "Help" section (which loads after the input element), but not when I loaded the javascript code in the question text section (which runs before the input element exists).

Jason
 
Logged Logged  
 
Last Edit: 2008/07/23 03:44 By jcleeland.
  The administrator has disabled public write access.
#16540
Mazi (Moderator)
Moderator Lime
Posts: 2760
graph
User Offline Click here to see the profile of this user
Re:entering the survey answer automatically 2 Months, 2 Weeks ago Karma: 19  
And remember that you have to put this setting into config.php to run javascript:
Code:

$filterxsshtml = false;
 
Logged Logged  
 
Beste Grüße/Best regards,
Mazi
______________________
You can support Limesurvey, too!
  The administrator has disabled public write access.
#16582
Mark B (User)
Fresh Lemon
Posts: 5
graphgraph
User Offline Click here to see the profile of this user
Re:[done] entering the survey answer automatically 2 Months, 2 Weeks ago Karma: 0  
Thanks for your help, I got it working...but with limitations:
1 - the code to force the answer must be in the help section of the question for which you want to set the answer. I tried the same code:

<script type="text/javascript">
document.getElementById('answer95716X111X1036'.value = 'Try 4';
</script>

in numerous other places after the question 1036 and it did not work. Including in the same group and in a subsequent group of questions.

2 - the question (1036 in this case) had to be shown, if I skipped it using conditions the answer was left as "No Answer".

Is there a way to set the answer to question 1036 from an entirely different, subsequent, question? Does this have something to do with when these answers are posted to the survey databse?

Also - for those following this thread at home - the survey must be activated for this to work.
 
Logged Logged  
  The administrator has disabled public write access.
Go to top