Jump to content
Sign in to follow this  
mickeymouse

Too Much Time! & Pass Focus Problem.

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.

Share this post


Link to post
Share on other sites

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>

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...