Jump to content

Too Much Time! & Pass Focus Problem.


mickeymouse

Recommended Posts

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)'>
&#160;MM
<input style='text-align:center;width:30' name='mm' id='mm' required MaxLength=2 onkeyup='mytab(mm,dd)'>
&#160;DD
<input style='text-align:center;width:30' name='dd' id='dd' required MaxLength=2 onkeyup='mytab(dd,sub)'>

Edited by mickeymouse
Had not finished defining problem.
Link to comment
Share on other sites

  • 2 weeks later...

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" />
    &#160;MM
    <input style="text-align:center;width:30" name="mm" id="mm" required maxlength="2" />
    &#160;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>

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...