I have a weird situation. I need to run an age calculation and it if the input is a certain age, lets say 18 or older, the result should return True – if 17 or younger it should return False. I have been trying, unsuccessfully to return the results to a text field.
Also, I dont know if there is a way to run the calculation without a button. I’d rather run the calculation after inputting the date.
This is what I have tried, I know the issue is with the if/else code and I am guessing the id in the last line.
<script>
function ageCalculator() {
var userinput = document.getElementById("BirthDate").value;
var BirthDate = new Date(userinput);
if(userinput==null || userinput=='') {
document.getElementById("message").innerHTML = "Please enter your Date of Birth!";
return false;
} else {
var month_diff = Date.now() - BirthDate.getTime();
var age_dt = new Date(month_diff);
var year = age_dt.getUTCFullYear();
var age = Math.abs(year - 1970);
return document.getElementById("result").innerHTML =
+ age ;
if (age >= 55) {
display: True;
} else if {
display: false;
}
}
}
</script>
<div style="clear: both;">
<h1>Please enter your Date of Birth so we can ensure the information you see is accurate.</h1>
<div class="form-inline SectionBox">
<input type=DateTextBox id=BirthDate emptymessage=MM/DD/YYYY required=True labeltext=Date of Birth:></div></div>
<button type="submit" onclick = "ageCalculator()"> Next </button> <br><br>
<input type=TextBox id=age required=false></div></div>
New contributor
1