Welcome, Guest
Username: Password: Remember me

TOPIC: Prefill for Array(Numbers)

Prefill for Array(Numbers) 6 months 3 weeks ago #100109

  • OlgaN
  • OlgaN's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 1
  • Karma: 0
Hi,

I have two columns and several rows in a question of type Array(Number), each answer drop-down list contains 60 options, which are numbers from 1 to 60. I would like to pre-fill all the drop-down lists so when the page is loaded they already have zeros as chosen options.

I tried two ways but non of them is working:

document.getElementById("#answer{SID}X{GID}X{self.qid}SQ001_SQ001").value = "0";

and

var selectId = 'answer{SID}X{GID}X{self.qid}SQ001_SQ001';
var defaultVal = 'input[id='+selectId+']';
$(defaultVal).val(0);

Could you, please, help me to find out what I am doing wrong and how it should be.
Thanks.
The administrator has disabled public write access.

Prefill for Array(Numbers) 6 months 3 weeks ago #100199

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
Try this:

<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
 
		var thisQuestion = $('#question{QID}');
 
		$('select', thisQuestion).each(function(i) {
 
			if($(this).val() == '') {
				$(this).val(0);
			}
		});
	});
</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.
The following user(s) said Thank You: OlgaN
Moderators: ITEd
Time to create page: 0.105 seconds
Donation Image