Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
Good evening to all!!!

I have a form in which i input age using the code:
Code: Select all
<cms:input name="dob" id="dob" type="datetime" class="input" required='1' />


I have to display the age automatically besides it once the year is entered (as a label). How can that be done?

I tried creating a function like:
Code: Select all
document.getElementById("dob_year").addEventListener("blur", myFunction);

function myFunction() {
    document.getElementById("dob_year").innerHTML = "<cms:show frm_dob_year />";
}


I used dob_year because that is the id the field gets on executing the couch code and converting it into html.

please advise.

Regards,
GenXCoders
Image
where innovation meets technology
Hey, year exclusively is not enough to determine age :)
Once you got full date entered by the user, some script should calculate how many full years have passed since entered date and 'now'. I think it's not a task for CMS, but only JS. Am I wrong in perception of your need?
@trendoman

I was thinking of a simpler approach.
Code: Select all
Current Year - Birth Year = Age in Years


To set the current year i am using:
Code: Select all
<cms:set curr_date="<cms:date format='Y' />" />


And on displaying the curr_date, we get the current year.
Code: Select all
<cms:show curr_date />


Now since the datetime input region creates three components in the HTML output, I got the region "dob_year".
Since the exact age is not going to be displayed anywhere it is not an issue. The age needs to be sent in the mail using <cms:send_mail> tag.

So I have created a label: "Approx. Age".
Seeing the age the client can decide whether to provide his services or not to the person. And he doesn't want to calculate the age manually. Its required so because:
1. Its Client requirement.
2. Services are according to age
3. Services are provided to an age group, say 18 to 20 yrs, 21 to 25 yrs, 26 to 30 yrs, etc.
Hence this approach.

As far as jQuery/JavaScript is concerned for the task, Both the values of the year, i.e. curr_date and dob can be substracted and resultant can be displayed. And that wont be a problem. But how to extract the values, is the concern.

Regards,
GenXCoders
Image
where innovation meets technology
Aashish, let me look at the template online or PM the file in skype and I'll try to help.
4 posts Page 1 of 1