Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: Change question labels based the current date

Change question labels based the current date 11 Monate 1 Woche her #95843

  • nuin
  • nuins Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 11
  • Karma: 0
Hi

We have a question (array numbers) with X and Y labels, where the Y labels are the past 6 months. Currently we are doing it manually, and my question is if there's a way to automate the process of changing the labels based on the current month of the year.

Thanks in advance
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Change question labels based the current date 11 Monate 1 Woche her #95861

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 3813
  • Dank erhalten: 683
  • Karma: 328
Do you want the months displayed ascending or descending?
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Change question labels based the current date 11 Monate 1 Woche her #95862

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 3813
  • Dank erhalten: 683
  • Karma: 328
Ignore that last question, we can do either with the same function.

Set up your survey to use JavaScript and add the following script to the source of the array question:
<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
		var qID = {QID};
 
		// Change this to true for ascending months
		var ascending = false;		
 
		// Find the current month
		var todayDate = new Date();
		var todayMonth = todayDate.getMonth();
 
		// Month labels
		var months = new Array();
		months[0]="January";
		months[1]="February";
		months[2]="March";
		months[3]="April";
		months[4]="May";
		months[5]="June";
		months[6]="July";
		months[7]="August";
		months[8]="September";
		months[9]="October";
		months[10]="November";
		months[11]="December";
 
		// Loop through the row labels
		$('#question'+qID+' .answertext').each(function(i) {
 
			// Do we want ascending? (don't edit here)
			if(ascending == true) {
				i = $('#question'+qID+' .answertext').length - (i+1);
			}
 
			// Find the month for this row
			if(todayMonth - i >= 0) {
				var monthIndex = todayMonth - i;
			}
			else {
				var monthIndex = 12 + todayMonth - i;
			}
 
			// Load the row label text
			$(this).text(months[monthIndex]);
		}); 
	});
</script>


The script will insert the months in descending order by default. If you want ascending, change:
var ascending = false;
To:
var ascending = true;
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Folgende Benutzer bedankten sich: nuin

Change question labels based the current date 11 Monate 5 Tage her #95994

  • nuin
  • nuins Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 11
  • Karma: 0
Thanks, works like a charm.

Just for reference, we wanted the months on the column headers, and the solution made the row names to be changed, changing

'#question'+qID+' .answertext'

to

'#question'+qID+' .col-responses'

gave us what we needed.

Thanks a lot
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd
Ladezeit der Seite: 0.617 Sekunden
Donation Image