mickeymouse 0 Posted December 18, 2019 Report Share Posted December 18, 2019 (edited) It takes 18/20 seconds to execute this code when I click my Submit Button- much much too long. Why? Also, why does it not pass focus to my "Submit" button upon completion? function formcheck(myform) {with (myform) if (yy.value.length!=2){alert('Year must be 2 digits.');yy.select();return false;} if (mm.value.length!=2){alert('Month must be 2 digits.');mm.select();return false;} if (dd.value.length!=2){alert('Day must be 2 digits.');dd.select();return false;} if (dd.value<'01' || dd.value>'31'){alert('Invalid Day.');dd.select();return false;} if (mm.value<'01' || mm.value>'12'){alert('Invalid Month.');mm.select();return false;} if (yy.value<'01' || yy.value>'99'){alert('Invalid Year.');yy.select();return false;} if (((mm.value == '04' || mm.value == '06' || mm.value == '09' || mm.value == '11') && dd.value > '30') || mm.value == '02' && dd.value > '29'){alert('Invalid Day for Month or visa versa.');dd.select();return false;} alert{'Finished');return false;}}}}}} <-------- Temporary in order to time the process. else{sub.focus;return true;}}}}}} <-------- Normal code to pass focus to "Submit" button BUT doesn't work! <form name=\"DateSetting\" action=\"HA_DateSet.php\" method=\"post\" onsubmit=\"return formcheck(DateSetting)\"> YY <input style='text-align:center;width:30' name='yy' id='yy' required MaxLength=2 onkeyup='mytab(yy,mm)'>  MM <input style='text-align:center;width:30' name='mm' id='mm' required MaxLength=2 onkeyup='mytab(mm,dd)'>  DD <input style='text-align:center;width:30' name='dd' id='dd' required MaxLength=2 onkeyup='mytab(dd,sub)'> Edited December 18, 2019 by mickeymouse Had not finished defining problem. Quote Link to post Share on other sites
Funce 42 Posted December 29, 2019 Report Share Posted December 29, 2019 I get zero delay with what you've provided (when I've corrected the errors) Is this test data somewhat accurate? <!DOCTYPE html> <html> <body> <form name="DateSetting" action="" method="post" onsubmit="return formcheck(DateSetting)"> YY <input style="text-align:center;width:30" name="yy" id="yy" required maxlength="2" />  MM <input style="text-align:center;width:30" name="mm" id="mm" required maxlength="2" />  DD <input style="text-align:center;width:30" name="dd" id="dd" required maxlength="2" /> <button type="submit" name="sub" id="sub">Submit</button> </form> </body> <script> function formcheck(myform) { with (myform) if (yy.value.length != 2) { alert("Year must be 2 digits."); yy.select(); return false; } if (mm.value.length != 2) { alert("Month must be 2 digits."); mm.select(); return false; } if (dd.value.length != 2) { alert("Day must be 2 digits."); dd.select(); return false; } if (dd.value < "01" || dd.value > "31") { alert("Invalid Day."); dd.select(); return false; } if (mm.value < "01" || mm.value > "12") { alert("Invalid Month."); mm.select(); return false; } if (yy.value < "01" || yy.value > "99") { alert("Invalid Year."); yy.select(); return false; } if ( ((mm.value == "04" || mm.value == "06" || mm.value == "09" || mm.value == "11") && dd.value > "30") || (mm.value == "02" && dd.value > "29") ) { alert("Invalid Day for Month or visa versa."); dd.select(); return false; } alert("Finished"); sub.focus; return true; } </script> </html> Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.