JSFiddle - React, Tailwind, and code Playground
by Tan
HTML
Duplicate Dropdowns:<br/>
<input id="age" type="tel" name="age" value="" onkeyup="copy('term');" />
<select id="term">
<option value="1">1 Month</option>
<option value="2">2 Months</option>
<option value="3">3 Months</option>
<option value="4">4 Months</option>
</select>
JavaScript
function copy(el) {
var select, option;
var test = document.getElementById(el);
for(var i=25; i >= 0;i--) {
test.remove(i);
}
var num = document.getElementById('age').value;
var val = 25
if (num > 60) {val=24;}
if (num > 61) {val=23;}
if (num > 62) {val=22;}
if (num > 63) {val=21;}
if (num > 64) {val=20;}
if (num > 65) {val=19;}
if (num > 66) {val=18;}
if (num > 67) {val=17;}
if (num > 68) {val=16;}
if (num > 69) {val=15;}
if (num > 70) {val=14;}
if (num > 71) {val=13;}
if (num > 72) {val=12;}
if (num > 73) {val=11;}
if (num > 74) {val=10;}
if (num > 75) {val=9;}
if (num > 76) {val=8;}
if (num > 77) {val=7;}
if (num > 78) {val=6;}
if (num > 79) {val=5;}
if (num > 80) {val=4;}
if (num > 81) {val=3;}
if (num > 82) {val=2;}
if (val == 2) {
option = document.createElement( 'option' );
option.text = "Maximum Age Reached";
option.value = "0";
test.add( option );
test.lastElementChild.selected = true;
}
else {
for ( var y = 3; y <= val; y += 1 ) {
option = document.createElement( 'option' );
option.text = y + " Years";
option.value = y;
test.add( option );
test.lastElementChild.selected = true;
}
}
}