Welcome, Guest
Username: Password: Remember me

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

Pre-fill Answer into question .. having trouble getting it to work. 3 years 7 months ago #58550

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: 3 years 7 months ago by Twinduct404. Reason: Second Question Added
The administrator has disabled public write access.

Re: Pre-fill Answer into question .. having trouble getting it to work. 3 years 7 months ago #58554

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4271
  • Thank you received: 806
  • Karma: 369
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Pre-fill Answer into question .. having trouble getting it to work. 3 years 6 months ago #58973

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

Re: Pre-fill Answer into question .. having trouble getting it to work. 3 years 6 months ago #59086

  • Mazi
  • Mazi's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 5331
  • Thank you received: 296
  • Karma: 249
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)limesurvey.org'"
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.143 seconds
Donation Image