Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:
  • Seite:
  • 1
  • 2

THEMA: how to display the age automatically

how to display the age automatically 1 Jahr 8 Monate her #90005

  • mimi
  • mimis Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 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.
Anhang:
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: how to display the age automatically 1 Jahr 8 Monate her #90007

  • Ben_V
  • Ben_Vs Avatar
  • OFFLINE
  • Platinum Lime
  • Beiträge: 1069
  • Dank erhalten: 235
  • Karma: 74
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...
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: how to display the age automatically 1 Jahr 8 Monate her #90009

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4141
  • Dank erhalten: 767
  • Karma: 349
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: how to display the age automatically 1 Jahr 8 Monate her #90013

  • Ben_V
  • Ben_Vs Avatar
  • OFFLINE
  • Platinum Lime
  • Beiträge: 1069
  • Dank erhalten: 235
  • Karma: 74
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...
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: how to display the age automatically 1 Jahr 8 Monate her #90044

  • mimi
  • mimis Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 32
  • Karma: 0
yes... its identify card number. tQ mr.ben :)

aha...i c..tQ mr.tpartner.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: how to display the age automatically 1 Jahr 8 Monate her #90094

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4141
  • Dank erhalten: 767
  • Karma: 349
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: how to display the age automatically 1 Jahr 8 Monate her #90326

  • mimi
  • mimis Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 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
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: how to display the age automatically 1 Jahr 8 Monate her #90351

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4141
  • Dank erhalten: 767
  • Karma: 349
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: how to display the age automatically 1 Jahr 8 Monate her #90416

  • mimi
  • mimis Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: how to display the age automatically 1 Jahr 8 Monate her #90470

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4141
  • Dank erhalten: 767
  • Karma: 349
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
  • Seite:
  • 1
  • 2
Moderatoren: ITEd
Ladezeit der Seite: 0.164 Sekunden
Donation Image