Check out the LimeSurvey source code on GitHub!

Pre-fill Answer into question .. having trouble getting it to work.

More
5 years 10 months ago - 5 years 10 months ago #58550 by Twinduct404
First let me say sorry for creating yet another one of these topics.
I've read through the forum and found alot of examples. But I've been editing/ changing my code for 4 hours now and not getting what I'm looking for.

Simple layout: I need to do a simple calculation and then write that value of the calculation to the value of a question. Now I've figured out the calculation part. Now I just need to write the value to another place:

Current Code
<script>
$(document).ready(function() {
var x=0;
 
if ({INSERTANS:49825X1X1SQ001} = "A1"){
x=x+1;
}
 
if ({INSERTANS:49825X1X1SQ002} = "A1"){
x=x+1;
}
 
document.getElementById("answer49825X1X7").value = 'x'
});
 
</script>

So the value of X needs to be written to the answer value of Question 49825X1X7.

49825X1X1SQ001 & 49825X1X1SQ002 & 49825X1X7 is found on a prev page.

Another question. If I choose the value of a question (in the advance properties section) so that the question is 'always hidden'. Can I still write a value to it using the above method?
Last Edit: 5 years 10 months ago by Twinduct404. Reason: Second Question Added

Please Log in to join the conversation.

More
5 years 10 months ago #58554 by tpartner

49825X1X1SQ001 & 49825X1X1SQ002 & 49825X1X7 is found on a prev page.

You cannot use JavaScript to write to questions that are on different pages.

If I choose the value of a question (in the advance properties section) so that the question is 'always hidden'. Can I still write a value to it using the above method?

No, you need to use CSS or JavaScript to hide the question if you want to manipulate it with JavaScript.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 years 9 months ago #58973 by Twinduct404
Thanks for the response and sorry for the delay in mine.
I though something like this was the problem.

Got everything to work out fine now.

Please Log in to join the conversation.

More
5 years 9 months ago #59086 by Mazi
You're welcome!

If our hints have been helpful and you enjoy limesurvey please consider a donation to the team .
We do all this in our free time and you don't have to pay a penny for this software.

Without your help we can't keep this project alive.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form