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 8875313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:56:49+00:00 2026-06-14T18:56:49+00:00

I have problem with if condition. I write a script who should showing alert

  • 0

I have problem with if condition. I write a script who should showing alert when value from field #customer-age is less than 21 (the calculated age of person). The problem is – the alert is showing every time – when the value is less and greater than 21.

My html code is:

<div class="type-text">
<label for="birthday">Date1:</label>
<input type="text" size="20" id="birthday" name="birthday" value="" readonly="readonly" />
</div>

<div class="type-text">
<span id="customer-age" readonly="readonly"></span>
</div>

<span id="date_from_start">23/11/2012</span>

and script looks like:

function getAge() {
    var sday =  $('#date_from_start').html();
    var split_date1 = sday.split("/");  
    var todayDate = new Date(split_date1[2],split_date1[1] - 1,split_date1[0]);

    var bday = $('#birthday').val();
    var split_date2 = bday.split("/");
    var birthDate = new Date(split_date2[2],split_date2[1] - 1,split_date2[0]);

    var age = todayDate.getFullYear() - birthDate.getFullYear();
    var m = todayDate.getMonth() - birthDate.getMonth();
    if (m < 0 || (m === 0 && todayDate.getDate() < birthDate.getDate())) {
        age--;
    }
    return age;
}

var startDate = new Date("1935,01,01");

$('#birthday').datepicker({
    dateFormat: 'dd/mm/yy',
    dayNamesMin: ['Nie', 'Pon', 'Wt', 'Śr', 'Czw', 'Pt', 'Sob'],
    dayNames: ['Niedziela','Poniedzialek','Wtorek','Środa','Czwartek','Piątek','Sobota'],
    monthNamesShort: ['Sty', 'Lut', 'Mar', 'Kwi', 'Maj', 'Cze', 'Lip', 'Sie', 'Wrz', 'Paź', 'Lis', 'Gru'],    
    changeMonth: true,
    changeYear: true,
    numberOfMonths: 1,
    constrainInput: true, firstDay: 1, dateFormat: 'dd/mm/yy',
    yearRange: '-77:-18',
    defaultDate: startDate,
    onSelect: function(dateText, inst) {
        $('#customer-age').html(getAge(new Date(dateText)));
        var cage = $('#customer-age').val();
          if (cage < 21)
             {
             alert('< 21 year');
             }
          else {
          }
    },
    maxDate: +0
});

The workin code you can check on http://jsfiddle.net/amarcinkowski/DmYBt/

  • 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-06-14T18:56:52+00:00Added an answer on June 14, 2026 at 6:56 pm

    change your line from:

    var cage = $('#customer-age').val();
    

    to

    var cage = parseInt($('#customer-age').html(), 10);
    

    jsFiddle

    Added:
    do you mean like:

    var infoContent = $.trim( $("#info").html() );
    alert( infoContent );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im facing following problem I have created mentioned condition, but when I choose y
I have problem with UIWebView delay when the load image from url. In my
I have a problem with Loop through a using the condition that an attribute
Is there a better way to write this I have A Condition which previous
Classic producer-consumer-problem. I have x app servers which write records in a DB table
I have file with jspx extension i write javascript like function isNumber(inputId){ var value
I need to script my app (not a game) and I have a problem,
I'm a beginner at SQL and have this fairly easy conditional problem: Every installation
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar
I have problem with my query on C, I’m using the oci8 driver. This

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.