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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:19:17+00:00 2026-06-18T11:19:17+00:00

I have a small trouble that would be great to have some help with.

  • 0

I have a small trouble that would be great to have some help with. I am creating a small form that I want to take a current date formatted 'dd/mm/yyyy' and add a year(s) variable from a drop-down box to create a final expiry date. The only trouble is that I do not know how to parse the start-date as a date variable in order to complete the calculation. Any thoughts or help would be greatly appreciated. Paul.

<script>
    $(document).ready(function () {
        $("#registerfor, #startdate, ").change(function () {
            // Get Variables
            var startdate = $("#startdate").val();
            var registerfor = $("#registerfor").val();
            // Add Years to Date
            var expirydate = startdate + registerfor;
            // Send Result on
            $("#expires").val(expirydate);
        });
    });
</script>
<input name="startdate" id="startdate" value="dd/mm/yyyy" />
<select id="registerfor" name="registerfor">
    <option value="1">1 Year</option>
    <option value="2">2 Years</option>
    <option value="3">3 Years</option>
</select>
  • 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-18T11:19:18+00:00Added an answer on June 18, 2026 at 11:19 am

    Sometimes what looks like quite a straight forward task becomes quite complicated.

     $(document).ready( function () {
    
        $("#registerfor, #startdate").change( function () {
    
            var str = $("#startdate").val();
    
            if( /^\d{2}\/\d{2}\/\d{4}$/i.test( str ) ) {
    
                var parts = str.split("/");
    
                var day = parts[0] && parseInt( parts[0], 10 );
                var month = parts[1] && parseInt( parts[1], 10 );
                var year = parts[2] && parseInt( parts[2], 10 );
                var duration = parseInt( $("#registerfor").val(), 10);
    
                if( day <= 31 && day >= 1 && month <= 12 && month >= 1 ) {
    
                    var expiryDate = new Date( year, month - 1, day );
                    expiryDate.setFullYear( expiryDate.getFullYear() + duration );
    
                    var day = ( '0' + expiryDate.getDate() ).slice( -2 );
                    var month = ( '0' + ( expiryDate.getMonth() + 1 ) ).slice( -2 );
                    var year = expiryDate.getFullYear();
    
                    $("#expires").val( day + "/" + month + "/" + year );
    
                } else {
                    // display error message
                }
            }
        });
    });
    

    Here is a fiddle so you can see it in action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have small problem, and would very much appreciate help :) I should convert byte
I have a small database that I need help designing. I have a VB.NET
So here's some code that I'm having trouble with: //format the date to a
I have a small class hierarchy that I'm having trouble implementing copyWithZone: for. I've
I have a small problem that would seem to be easy to solve, but
I have a small task in Flash, that I'm having a little trouble with.
I have small web app that generate PDF files as a report. I'm trying
I have a small Silverlight 4 app that essentially consists of a grid containing
I have an existing application that I'm supposed to take and create a mini
So, I work in a fairly small IT section. We have a trouble ticketing

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.