Welcome, Guest
Username: Password: Remember me

TOPIC: Pre-filling answer text for questions

Pre-filling answer text for questions 3 years 6 days ago #64888

  • cbc2132
  • cbc2132's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
Hi -

I'm trying to pre-fill the answer text to a question in v1.91. I've tried every variation of javascript I can think of but nothing seems to work.

For example -

For a question, I've included the below snippet in it's question field. I've also tried to include the javascript in a separate question on a previous page, but that hasn't worked either.

i.e.

<script type="text/javascript">
document.getElementById("answer496692207").value = 'test';
</script>

What am i doing wrong? Please help!

Thanks!
Cadran
The administrator has disabled public write access.

Re: Pre-filling answer text for questions 3 years 6 days ago #64890

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4130
  • Thank you received: 763
  • Karma: 347
The ID doesn't look right - you're missing the "X"s in the SGQA. The ID should be like "answer{SID}X{GID}X{QID}".

Also, I don't think you should do anything until the page is fully loaded.

Something like:
<script type="text/javascript" charset="utf-8">
 
	// Wait for the DOM to load
	$(document).ready(function() {
 
		document.getElementById("answer49669X22X07").value = 'test';
 
	});
 
</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.

Re: Pre-filling answer text for questions 3 years 6 days ago #64892

  • cbc2132
  • cbc2132's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
Thank you for the response!

Yes I didn't give a proper example SGQA, but the one I'm using in my code is correct. I tried making the change you suggested, but no luck.


If i would like answer49669X22X07 to display 'test', then do I include the javascript in Question 49669X22X07, or somewhere else?

thanks!
The administrator has disabled public write access.

Re: Pre-filling answer text for questions 3 years 6 days ago #64894

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4130
  • Thank you received: 763
  • Karma: 347
The script needs to go in the source of a question or group description on the same page as the element(s) you are trying to manipulate.

Did you turn off the XSS filter? Are there any JS errors? Can you get a simple JS alert to work?

Try jQuery:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		$('#answer49669X22X07').val('Your inserted value');
 
	});
 
</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.

Re: Pre-filling answer text for questions 3 years 5 days ago #64905

  • cbc2132
  • cbc2132's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
Ok - that's where I've been putting the script. The XSS filter is off. I'm not receiving and errors and I'm able to run other scripts, such as alerts and adding text to the question body. For some reason though, adding text the the answer field is not working. Thanks!
The administrator has disabled public write access.

Re: Pre-filling answer text for questions 3 years 5 days ago #64907

  • cbc2132
  • cbc2132's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
the jquery worked! thanks
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.117 seconds
Donation Image