Code subject: validate age entered as selection box in javascript
Posted: Wed Oct 26, 2011 12:12 am
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2279 Location: Earth Has thanked: 39 time Have thanks: 61 time
Following code check enter as <select> options as day,month and year.
Code:
function checkAgeCheckBox(f){ var dob=new Date(); var date=dob.getDate(); var month=dob.getMonth() + 1; var year=dob.getFullYear(); var cmbmonth=parseInt(document.getElementById("cmbmonth").options[document.getElementById("cmbmonth").selectedIndex].value); var cmbday=parseInt(document.getElementById("cmbday").options[document.getElementById("cmbday").selectedIndex].value); var cmbyear=parseInt(document.getElementById("cmbyear").options[document.getElementById("cmbyear").selectedIndex].value); age=year-cmbyear; if(cmbmonth>month){age--;} else{if(cmbmonth==month && cmbday>=date){age--;}} if(cmbmonth==0){return false;} else if(cmbday==0){return false;} else if(cmbyear>=2005){return false;} else if(age<'.$age.'){ return true; }
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )