JSFiddle - React, Tailwind, and code Playground

by GaryC123

HTML

Start Year<input type="text" id="startyear" onchange="calculate_years()">
<br>
    End Year
<input type="text" id="endyear" onchange="calculate_years()">
    <br>
        Number of years
<input type="text" id="years">

JavaScript

function calculate_years(){
    sy=document.getElementById("startyear").value
    ey=document.getElementById("endyear").value
    if(Number(sy)>0 && Number(ey)>0){
        document.getElementById("years").value=ey-sy
    }
    else{
        document.getElementById("years").value=""
    }
}