Is Date A Leap Year

[Total: 0    Average: 0/5]

This example shows how you can use a form to validate the day and month entered.

Body Code:

<form name=exf1>
Input the date:<BR>
[DAY 1-31]:<input type=text name=day value="1" onblur="validate()"><BR>
[MONTH 1-12]:<input type=text name=month value="1" onblur="validate()"><BR>
[YEAR]:<input type=text name=year value="2000" onblur="validate()"><BR>
<input type=button name=check onclick="computeIt()" value="Is This A Leap Year?"><BR>
Is A LeapYear:<input type=text name=isleap value="<?>"><BR>
</form>
<script type=text/javascript>
function computeIt() {
  var _isLeap = false;
  var _year = parseInt(Math.round(parseFloat(document.exf1.year.value)));
  _isLeap = (_year % 4 == 0 && (_year % 1000 == 0 || _year % 100 != 0));
  document.exf1.isleap.value = _isLeap?"Yes":"No";
}
function setToMinOrMax(_a,_min,_max) {
  var _ret = parseInt(Math.round(parseFloat(_a)));
  _ret = _ret < _min ? _min : _ret > _max ? _max : _ret;
  return (_ret);
}
function validate() {
  document.exf1.day.value   = setToMinOrMax(document.exf1.day.value,  1,31);
  document.exf1.month.value = setToMinOrMax(document.exf1.month.value,1,12);
  document.exf1.isleap.value = "<?>";
}
</script>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *