1// JavaScript Document 2function validateForm() { 3 var fname = document.getElementById('fname').value; 4 var lname = document.getElementById('lname').value; 5 var gender = valButton(document.getElementsByName('gender')); 6 var frmMonth = document.getElementById('frmMonth').value; 7 var frmDay = document.getElementById('frmDay').value; 8 var frmYear = document.getElementById('frmYear').value; 9 var birthplace = document.getElementById('birthplace').value; 10 var country = document.getElementById('country').value; 11 var club_name = trim(document.getElementById('club_name').value); 12 13 var nationality = document.getElementById('nationality').value; 14 15 var reg = /^[0-9]+$/; 16 if (fname == '') { 17 alert('Please enter first name'); 18 document.getElementById('fname').focus(); 19 return false; 20 } else if (lname == '') { 21 alert('Please enter last name'); 22 document.getElementById('lname').focus(); 23 return false; 24 } else if (gender == null) { 25 alert('Please select gender'); 26 document.getElementById('gender').focus(); 27 return false; 28 } else if ( ! isValidDate(frmDay, frmMonth, frmYear ) ) { 29 alert('The date you entered is not a valid date') ; 30 document.getElementById('frmDay').focus(); 31 return false ; 32 } else if (birthplace == '') { 33 alert('Please enter place of birth'); 34 document.getElementById('birthplace').focus(); 35 return false; 36 } else if (country == '' || country == 0) { 37 alert('Please select country of birth'); 38 document.getElementById('country').focus(); 39 return false; 40 } else if (nationality == '' || nationality == 0) { 41 alert('Please select nationality'); 42 document.getElementById('nationality').focus(); 43 return false; 44 } else if (club_name == '') { 45 alert('Please enter your club name'); 46 document.getElementById('club_name').focus(); 47 return false; 48 } 49 50} 51function valButton(btn) { 52 var cnt = -1; 53 for ( var i = btn.length - 1; i > -1; i--) { 54 if (btn[i].checked) { 55 cnt = i; 56 i = -1; 57 } 58 } 59 if (cnt > -1) 60 return btn[cnt].value; 61 else 62 return null; 63} 64function trim(str) { 65 var str = str.replace(/^\s\s*/, ''), ws = /\s/, i = str.length; 66 while (ws.test(str.charAt(--i))) 67 ; 68 return str.slice(0, i + 1); 69} 70function isValidDate(day, month, year) { 71 /* 72 * Purpose: return true if the date is valid, false otherwise 73 * 74 * Arguments: day integer representing day of month month integer 75 * representing month of year year integer representing year 76 * 77 * Variables: dteDate - date object 78 * 79 */ 80 var dteDate; 81 82 // set up a Date object based on the day, month and year arguments 83 // javascript months start at 0 (0-11 instead of 1-12) 84 month = month -1 ; 85 dteDate = new Date(year, month , day); 86 87 /* 88 * Javascript Dates are a little too forgiving and will change the date 89 * to a reasonable guess if it's invalid. We'll use this to our 90 * advantage by creating the date object and then comparing it to the 91 * details we put it. If the Date object is different, then it must have 92 * been an invalid date to start with... 93 */ 94 95 return ((day == dteDate.getDate()) && (month == dteDate.getMonth()) && (year == dteDate 96 .getFullYear())); 97}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.