Ticker

10/recent/ticker-posts

Header Ads Widget

How to create a simple webpage to calculate retirement date.


To create a html, css and Java script code for calculation of retirement date is given as follows. You can apply necessary changes according to your need. 

To create webpage for calculation of retirement date You need to to use HTML for basic structure, CSS for its styling to make it more user experiensive and Use JavaScript to make it interactive. These three languages has been used to design the Webpage to calculate retirement date. Explore the following code structure.

<!DOCTYPE html>
<html>
<head>
    <title>Retirement Date Calculator</title>
    <style>
/* Add css style to make it to look beautiful*/
    label {
        display:block;
        margin:10px auto;
        text-align:center;
        color:white;
        font-size:22px;
        font-weight:800;
    }
    input[type=date], input[type=number] {
        display:block;
        margin:10px auto;
        font-size:22px;
        padding:5px;
    }
    #retire-btn {
        display:block;
        margin:10px auto;
        font-size:25px;
        font-weight:800;
        padding:5px;
        border-radius:8px;
    }
    </style>
</head>
<body>
<div style="background:green; padding:20px;">
    <h1 style="color:white;text-align:center;">Retirement Date Calculator</h1>
    <label for="dob">Date of Birth:</label>
    <input type="date" id="dob"><br><br>

    <label for="retirementAge">Retirement Age:</label>
    <input type="number" id="retirementAge" min="1" max="100" value="62"><br><br>

    <button id="retire-btn" onclick="calculateRetirementDate()">Calculate</button><br><br>

    <h2 style="color:white;text-align:center;">Retirement Date:</h2>
    <p style="color:white;text-align:center;font-size:25px; font-weight:800;"id="retirementDate"></p>

    <script>
//JavaScript function start

        function calculateRetirementDate() {
            var dob = new Date(document.getElementById("dob").value);
            var retirementAge = parseInt(document.getElementById("retirementAge").value);
            var retirementDate = new Date(dob.getFullYear() + retirementAge, dob.getMonth(), dob.getDate());

            var options = { year: 'numeric', month: 'long', day: 'numeric' };
            var formattedDate = retirementDate.toLocaleDateString(undefined, options);

            document.getElementById("retirementDate").innerHTML = "You will retire on " + formattedDate + ".";
        }
//End of javascript function
    </script>
    </div>
</body>
</html>

For live preview click below

LIVE PREVIEW

Post a Comment

0 Comments