Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: How to change default value in array

How to change default value in array 3 years 7 months ago #58252

Actually the subject summarizes it pretty well. How can I change the default value in an array from "No answer" to something else (Limesurvey 1.90)?

Best regards

Martin
The administrator has disabled public write access.

Re: How to change default value in array 3 years 7 months ago #58290

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4270
  • Thank you received: 803
  • Karma: 368
If you want to change it for all surveys, see translating LimeSurvey - docs.limesurvey.org/tiki-index.php?page=...anslate%20LimeSurvey.

For individual questions, set up your survey to use JavaScript and add the following to the source of the array. Replace "QQ" with the array ID and modify the text as necessary.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		var qID = QQ;
		var originalText = 'No answer';
		var newText ='Some new text';
 
		$('#question'+qID+' table.question thead th').filter(function() {
			return $(this).text() == originalText;
		})
		.text(newText);
 
	});
 
</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: How to change default value in array 3 years 7 months ago #58301

Thank you very much, although I have to admit that I am a little disappointed that a software so mature otherwise requires me to do a JS hack just to change a default value :(
The administrator has disabled public write access.

Re: How to change default value in array 3 years 7 months ago #58302

  • Matherion
  • Matherion's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 18
  • Karma: 0
Hey guys,

I happen to be trying exactly the same thing. However, although the code runs without any errors indicated by Firebug, nothing happens. Sadly, however, I don't actually know Javascript. I know PHP a bit, but I'm not sure what's happening here, so I basically get stuck pretty quickly trying to debug :-/

This is what I have so far. The question is just an 'array' question type (i.e. radiobuttons). Maybe I misunderstood the original question (because why would anything say "No answer" with this question type?), but as you may understand already, I'm not overly secure about my understanding of Limesurvey or Javascript :-/

This is the code I use now:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		var qID = '68955X75X1426';
		var originalText = 'No answer';
		var newText ='1';
 
		$('#question'+qID+' table.question thead th').filter(function() {
			return $(this).text() == originalText;
		})
		.text(newText);
 
	});

The code of the first (of 7) answer options I want to be selected by default is 1 (the others are 2-7). The codes of the eight subquestions are also 1-8.

Thank you in advance!

PS: Martin: I have high hopes of Limesurvey 2 - I'm already very impressed by 1.9, but I have a feeling 2 is going to contain some pretty radical improvements. No idea why I have that feeling, but I do :-)
The administrator has disabled public write access.

Re: How to change default value in array 3 years 7 months ago #58304

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4270
  • Thank you received: 803
  • Karma: 368
although I have to admit that I am a little disappointed that a software so mature otherwise requires me to do a JS hack just to change a default value
Complaints can be submitted with our paychecks.
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: How to change default value in array 3 years 7 months ago #58305

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4270
  • Thank you received: 803
  • Karma: 368
Matherion, there are two problems with your code - you are missing the </script> closing tag and the qID variable is just supposed to be the question ID, not the whole SGQA:
Untitled-4_2011-03-15.png



Having said that, I don't think it will achieve your goal.

Do you want the first option in each row selected by default?
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.
Last Edit: 3 years 7 months ago by tpartner.
The administrator has disabled public write access.

Re: How to change default value in array 3 years 7 months ago #58309

  • Matherion
  • Matherion's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 18
  • Karma: 0
Dear tpartner,

sorry, the missing </script> was a copy paste error, my apologies!
And indeed, even corrected it does not achieve my goal :-)

Indeed, I would like to have the first option selected by default. People indicate the degree to which they perform a variety of functions, and most people will only perform one or two functions, so it's a userfriendliness (or, participantfriendliness :-)) thing, not crucial. So if there's no simple answer, please don't bother too much! I should learn how to do this stuff myself at some point anyway :-) In any case, thank you very much for your reaction so far!
The administrator has disabled public write access.

Re: How to change default value in array 3 years 7 months ago #58313

  • Matherion
  • Matherion's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 18
  • Karma: 0
Hey guys,

I managed to do what I wanted, it was very simple. So simple that even I understand it :-) I assume you both know already how to do this, but I'm just posting my solution in case anybody else ends up here looking for the same.
	$(document).ready(function(){
          document.getElementById('answer68955X75X14261-1').checked= true;
          document.getElementById('answer68955X75X14262-1').checked= true;
          document.getElementById('answer68955X75X14263-1').checked= true;
          document.getElementById('answer68955X75X14264-1').checked= true;
          document.getElementById('answer68955X75X14265-1').checked= true;
          document.getElementById('answer68955X75X14266-1').checked= true;
          document.getElementById('answer68955X75X14267-1').checked= true;
	});

So, basically, you take the SGQA, add a dash and the answer option you want selected, and you 'check' it.
The administrator has disabled public write access.

Re: How to change default value in array 3 years 7 months ago #58314

  • Matherion
  • Matherion's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 18
  • Karma: 0
Question. Can you have pieces of code for this "$(document).ready(function(){})" thing in several questions? Or would you then have to collect all code in one question, or say in the Group Description?
The administrator has disabled public write access.

Re: How to change default value in array 3 years 7 months ago #58315

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4270
  • Thank you received: 803
  • Karma: 368
Can you have pieces of code for this "$(document).ready(function(){})" thing in several questions?
You can have as many as yo like. They will just fire sequentially.
So, basically, you take the SGQA, add a dash and the answer option you want selected, and you 'check' it.
Yep, that will work but if you want to allow respondents to return to the page, you may want to throw in a test for checked radios:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		var qID = QQ;
 
		// Loop through the rows and check the first radio if none are already checked
		$('#question'+qID+' table.question tbody tr').each(function(i) {
			if($('input.radio:checked', this).length == 0) {
				$('input.radio:eq(0)', this).attr('checked', true);
			}
		}); 
	});
 
</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.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.234 seconds
Donation Image