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

TOPIC: how to display the age automatically

how to display the age automatically 1 year 11 months ago #90005

  • mimi
  • mimi's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 32
  • Karma: 0
hi...

i have two question here...

1)I would like to know how to display the age automatically if ic num has been added to the system. can lime survey do it?

2)and how about if i want to put the array type question here but with different number of arrays. here i have attached the view of question that i meant for the second question.

hope there who are willing to help.

thank you.
Attachments:
The administrator has disabled public write access.

Re: how to display the age automatically 1 year 11 months ago #90007

  • Ben_V
  • Ben_V's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 1147
  • Thank you received: 273
  • Karma: 79
Hello,

1) for the less, it's possible from date of birth
No idea how to adapt this for ic num.
Ben
Benoît

goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
The administrator has disabled public write access.

Re: how to display the age automatically 1 year 11 months ago #90009

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4360
  • Thank you received: 827
  • Karma: 381
1) What is an "ic num"?

2) You can hide the unwanted radio buttons with CSS. Use a tool like Firebug for Firefox to identify them.
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 display the age automatically 1 year 11 months ago #90013

  • Ben_V
  • Ben_V's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 1147
  • Thank you received: 273
  • Karma: 79
probably "identity card number" :)
Benoît

goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
The administrator has disabled public write access.

Re: how to display the age automatically 1 year 11 months ago #90044

  • mimi
  • mimi's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 32
  • Karma: 0
yes... its identify card number. tQ mr.ben :)

aha...i c..tQ mr.tpartner.
The administrator has disabled public write access.

Re: how to display the age automatically 1 year 11 months ago #90094

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4360
  • Thank you received: 827
  • Karma: 381
Can you give us an example of the IC number format? (we don't use them here)
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 display the age automatically 1 year 11 months ago #90326

  • mimi
  • mimi's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 32
  • Karma: 0
910110-10-5555

910110-based on the day of birth. it means the person birth on 10/01/1991
10-based on the place of birth.means the country.
5555-this represents generic serial numbers. The odd numbers for the last num denotes male while the even numbers denote female

tQ
The administrator has disabled public write access.

Re: how to display the age automatically 1 year 11 months ago #90351

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4360
  • Thank you received: 827
  • Karma: 381
I'm still not clear on the date format. Is "910110" in the YYMMDD or YYDDMM format (your example could be either).
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 display the age automatically 1 year 11 months ago #90416

  • mimi
  • mimi's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 32
  • Karma: 0
its already my own example.huhu. the num that i give is just only an example. it can be any num. and 910110 is YYMMDD.
The administrator has disabled public write access.

Re: how to display the age automatically 1 year 10 months ago #90470

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4360
  • Thank you received: 827
  • Karma: 381
Okay, if you have two text inputs on a page, the first being the IC input and the second being the age:

1) Add the following to the end of template.js:
function icToAge() {
 
	// A listener on the first input
	$('input.text:eq(0)').bind('input propertychange', function() {
 
		// Define the IC number format yymmdd-##-####
		var patternMatch = /^[0-9]{2}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])-[0-9]{2}-[0-9]{4}$/;
 
		var icInput = $(this).val();
 
		if (patternMatch.test(icInput) != true) {
			// Invalid IC number format
			$('input.text:eq(1)').val('No age available.');
		}
		else {
			var d = new Date();
			var todayYear = d.getFullYear();
			var todayShortYear = String(todayYear).substr(2,2); 
			var todayMonth = d.getMonth()+1; 
			var todayDate = d.getDate();
 
			var birthDateCode = icInput.split('-')[0];
			var birthYear = birthDateCode.substr(0,2);
			var birthMonth = birthDateCode.substr(2,2);
			var birthDate = birthDateCode.substr(4,2);
			if(birthYear > todayShortYear) {
				birthYear = 19+birthYear;
			}
			else {
				birthYear = 20+birthYear;
			}
 
			var age = todayYear - birthYear;
 
			if ( todayMonth < birthMonth) {
				age--;
			}
			else if ((birthMonth == todayMonth) && (todayDate < birthDate)) {
				age--;
			}
 
			// Load the age into the second input
			$('input.text:eq(1)').val(age);
		}
 
	});
}

2) Add this to the source of the IC input question to call the icToAge() function:
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		icToAge();
	});
</script>

Some notes:
- The icToAge() function validates an IC input against a regular expression and if it passes, the current age is calculated and inserted in the next text input.
- This code is designed for a page where the IC input is the first text input and the age is the second.
- The function resides in template.js because Expression Manager destroys valid regular expressions if placed in the question source.
- The validation regex could probably use some tuning for 30-day-months, etc - I just did it quickly for this example.
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.134 seconds
Donation Image