Welcome, Guest
Username: Password: Remember me

TOPIC: Creating a new question type in 1.9?

Creating a new question type in 1.9? 3 years 10 months ago #51822

  • rhodebump
  • rhodebump's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
Is there any guide or documentation on adding a new question type to version 1.9?

I want to create question type that allows users to input a date, and the question type will calculate the age. I realize that there are javascript solutions to this, but would rather do it serverside.

Thanks.
The administrator has disabled public write access.

Re:Creating a new question type in 1.9? 3 years 10 months ago #51832

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5325
  • Thank you received: 296
  • Karma: 249
It is very complicated to create new question types, I don't recommend this approach.

Better calculate the age at data analysis, tools like Excel or SPSS should be able to do so.

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.

Re:Creating a new question type in 1.9? 3 years 10 months ago #51839

  • rhodebump
  • rhodebump's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
I need to do it in the survey itself since I am using the age to perform branching.

Thanks.
The administrator has disabled public write access.

Re:Creating a new question type in 1.9? 3 years 10 months ago #51850

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6334
  • Thank you received: 818
  • Karma: 243
Maybe you can calculate the age in javascript (see www.google.com/search?q=age+calculation+javascript ).

And fill another question with this number .

To hide this question , use css or javascript

docs.limesurvey.org/tiki-index.php?page=...ime+using+Javascript
The administrator has disabled public write access.

Re:Creating a new question type in 1.9? 3 years 10 months ago #51855

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5325
  • Thank you received: 296
  • Karma: 249
I think you can use conditions on a simply date field. So if you have an end date at your survey e.g. 2010-11-30 you can use a constant as comparison operator at the conditions.

The other solution, as Shnoulle mentioned, is to calculate the age by javascript and populate a hidden question.

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.

Re:Creating a new question type in 1.9? 3 years 10 months ago #51910

  • rhodebump
  • rhodebump's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
I ended up using the javascript way. Here's what I used (for benefit of others that may do this)
<script>
jQuery(document).ready(
    function(){
       // alert('onload alert!');
 
$('#answer48818X1X2').change(function() {
	var dob= $('#answer48818X1X2').val();
	var dobDate= new Date(dob);
	var birth_year = dobDate.getYear();
	var birth_month =dobDate.getMonth(); 
	//alert ("you set the dob " + dob);
 	var today_date = new Date();
  	var  today_year = today_date.getYear();
   	var today_month = today_date.getMonth();
 	var   today_day = today_date.getDate();
  	var  age = (today_year) - birth_year;
    	if ( today_month < (birth_month - 1))
   	{
      		age--;
    	}
    	if (((birth_month - 1) == today_month) && (today_day < birth_day))
    	{ 
      		age--;
    	}
 
	$('#answer48818X1X486').val(age);
 
});
 
    }
 
);
</script>
The administrator has disabled public write access.

Re:Creating a new question type in 1.9? 3 years 10 months ago #51918

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5325
  • Thank you received: 296
  • Karma: 249
Can you please add your solution to the workaround section of our manual so other users can beneffit from your solution, too!?

Thanks!

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.

Aw: Re:Creating a new question type in 1.9? 2 years 4 months ago #79176

  • barbarian
  • barbarian's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 13
  • Karma: 0
Can someone tell me, how I can change this code from input-format mm/dd/yyyy to dd.mm.yyyy?

I tried a lot, but nothing works. The code for itself works fine!

Thank you!
The administrator has disabled public write access.

Aw: Creating a new question type in 1.9? 2 years 4 months ago #79365

  • barbarian
  • barbarian's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 13
  • Karma: 0
Here comes the solution for changing the date format!
jQuery(document).ready(
    function(){
       // alert('onload alert!');
 
$('#answer48569X47X1050').change(function() {
	var dob= $('#answer48569X47X1050').val();
	// neu:
var dobParts = dob.split(".");
 
// neu:
// Datumsformat umbauen und dob damit überschreiben
dob = dobParts[1] + '/' + dobParts[0] + '/' + dobParts[2];
	var dobDate= new Date(dob);
	var birth_year = dobDate.getYear();
	var birth_month =dobDate.getMonth(); 
	//alert ("you set the dob " + dob);
 	var today_date = new Date();
  	var today_year = today_date.getYear();
   	var today_month = today_date.getMonth();
 	var today_day = today_date.getDate();
  	var age = (today_year) - birth_year;
    	if ( today_month < (birth_month - 1))
   	{
      		age--;
    	}
    	if (((birth_month - 1) == today_month) && (today_day < birth_day))
    	{ 
      		age--;
    	}
 
	$('#answer48569X47X1052').val(age);
 
});
 
    }
 
);
The administrator has disabled public write access.

Re: Aw: Creating a new question type in 1.9? 2 years 4 months ago #79383

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5325
  • Thank you received: 296
  • Karma: 249
Vielen Dank für dein Feedback. Bitte das neue Feature auch ins Wiki übertragen, da das forum hin und wieder bereinigt wird und es wäre schade, solche Lösungen dadurch zu verlieren.

Danke!

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.178 seconds
Donation Image