Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6964509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:56:02+00:00 2026-05-27T15:56:02+00:00

I’m trying to derive the users age from DOB using a script, then depending

  • 0

I’m trying to derive the users age from DOB using a script, then depending on this age award them points for two areas Federal(f) and Quebec(q) Immigration, as they both calculate age points i have a set of if…else commands to award points and display them in two textboxes.
currently the script for calcualting the points parseInt’s the text field that displays the age(this field is populated by the dobtoage script)
heres my code and a live preview.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Quebec and Federal Immigration Points Calculator</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
</head>
<body>
<form name="form">
<p>Your Date of Birth (format:<strong>dd/mm/yyyy</strong>)</p><br />
<input onmouseout="showAge()" name="dob" id="dob" />
<p>Your Age</p><input name="age" type="text" style="font-size: 15px" value="" size="7" readonly>
<INPUT NAME="calc" VALUE="Calculate" TYPE="button" onClick="compute(this.form)"><br />
<input name="rsltf" type="text" style="font-size: 50px" value="" size="20" readonly /><br />
<input name="rsltq" type="text" style="font-size: 50px" value="" size="20" readonly />
</form>
<script type="text/javascript"> 
function showAge(){ 
var d =document.getElementById('dob').value.split('/'); 
var today=new Date(); 
var bday=new Date(d[2],d[1],d[0]); 
var by=bday.getFullYear(); 
var bm=bday.getMonth()-1; 
var bd=bday.getDate(); 
var age=0; var dif=bday; 
while(dif<=today){ 
var dif = new Date(by+age,bm,bd); 
age++; 
} 
age +=-2 ; 
form.age.value = age; 
} 
</script> 
<script type="text/javascript">
function compute(form)
{
var a = parseInt(form.age.value, 10) || 0; 
if (a == 17)
   {
   f = 2; q = 0; 
   }
   else if (a == 53)
   {
   f = 2; q = 0;
   }
   else if (17 > a > 53)
   {
   f = 0; q = 0;
   }
   else if (a == 19)
   {
   f = 6; q = 16;
   }
   else if (a == 51)
   {
   f = 6; q = 0;
   }
   else if (a == 18)
   {
   f = 4; q = 16;
   }
   else if (a == 20)
   {
   f = 8; q = 16;
   }
   else if (a == 50)
   {
   f = 8; q = 0;
   }
   else if (a == 52)
   {
   f = 4; q = 0;
   }
   else if (35 >= a >= 21)
   {
   f = 10; q = 16;
   }
   else if (a == 36)
   {
   f = 10; q = 14;
   }
   else if (a == 37)
   {
   f = 10; q = 12;
   }
   else if (a == 38)
   {
   f = 10; q = 10;
   }
   else if (a == 39)
   {
   f = 10; q = 8;
   }
   else if (a == 40)
   {
   f = 10; q = 6;
   }
   else if (a == 41)
   {
   f = 10; q = 4;
   }
   else if (a == 42)
   {
   f = 10; q = 2;
   }
   else if (a == 43)
   {
   f = 10; q = 0;
   }
   else if (50 >= a >= 44)
   {
   f = 10; q = 0;
   }
form.rsltf.value = f;
form.rsltq.value = q;   
}
</script>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:56:02+00:00Added an answer on May 27, 2026 at 3:56 pm

    First, you’re calculating age weirdly.

    Do this:

    var today = new Date(); 
    var bday = new Date(d[2],d[1],d[0]);
    var age = today.getFullYear() - bday.getFullYear();  //If you're born in 1980 then 2011-1980 means you're about 31 years old, this will give you the age if birthday has already passed
    
    if(today.getMonth() < bday.getMonth() || (today.getMonth() == bday.getMonth() && today.getDate() < bday.getDate()))  
    {
         age--;  //Reduce age by 1 if birthday hasn't passed
    }
    

    As to the giant if elseif structure, first I’d break it up into two separate structures. This allows you to take advantage of ranges in one that aren’t available in the other to shorten your overall structure. The age ranges are so jumbled up in it that I don’t really feel like picking through it to construct the appropriate structures. Might want to take advantage of switch case statements instead of if/elseif/else.

    Also, put your functions up in the head where they belong. Also, you need some error checking on the ShowAge() function in case it’s not a valid date. Also, you need use getElementById on the form’s id to change it’s value in ShowAge() at the end, otherwise it has no idea what form is. So, give your form an id and change the end of ShowAge() to:

    document.getElementById('formid').age.value = age; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.