Check out the LimeSurvey source code on GitHub!

Creating a new question type in 1.9?

More
6 years 3 months ago #51822 by rhodebump
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.

Please Log in to join the conversation.

More
6 years 3 months ago #51832 by Mazi
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)survey-consulting.com'"

Please Log in to join the conversation.

More
6 years 3 months ago #51839 by rhodebump
I need to do it in the survey itself since I am using the age to perform branching.

Thanks.

Please Log in to join the conversation.

More
6 years 3 months ago #51850 by DenisChenu
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

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).

Please Log in to join the conversation.

More
6 years 3 months ago #51855 by Mazi
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)survey-consulting.com'"

Please Log in to join the conversation.

More
6 years 3 months ago #51910 by rhodebump
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>

Please Log in to join the conversation.

More
6 years 3 months ago #51918 by Mazi
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)survey-consulting.com'"

Please Log in to join the conversation.

More
4 years 10 months ago #79176 by barbarian
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!

Please Log in to join the conversation.

More
4 years 9 months ago #79365 by barbarian
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);
 
});
 
    }
 
);

Please Log in to join the conversation.

More
4 years 9 months ago #79383 by Mazi
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)survey-consulting.com'"

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form