banjo
banjo

Reputation: 373

JS form validation not working in IE

Simple JS form validation does not seem to be working in IE. Any help would be grand. It seems to be submitting the form rather then giving me an alert when nothing is entered into the email field. works as intended in Chrome, FF, Opera, Safari, Just NOT in IE.

HTML

<form action="index.php" name="loginForm" onsubmit="return validateLoginForm();" method="post" >
    <div class="formBg">
      <input type="text" name="email" id="email" tabindex="1" class="formPos" value="" placeholder="Email" />
      <div class="loginText"><a href="#" class="linkOne">Forgot your password?</a></div>
    </div>
    <div class="formBg">
      <input type="password" name="password" id="password" tabindex="2" class="formPos" value="" placeholder="Password" />
      <div class="loginText">Keep me logged in</div>
    </div>
    <div id="loginBtnFrame">
      <div id="loginBtn">
        <input type="submit" name="submit" id="loginFormBtn" value=" " tabindex="3" />
      </div>
      <div class="slider-frame"><span class="slider-button">no</span></div>
      <input type="checkbox" value="1" id="rememberMe" name="rememberMe" />
    </div>
  </form>

Javascript

function validateLoginForm()
{
var x=document.forms["loginForm"]["email"].value;
if (x==null || x=="")
  {
  alert("email must be filled out");
  return false;
  }
}

Thank you so much in advance.

Upvotes: 0

Views: 2610

Answers (1)

banjo
banjo

Reputation: 373

For those that may hit the same issue.

I found that IE simple form validation conflicts with HTML or some Jquery 'placeholders'. I got around it by adding '(x==null || x=="" || x=="Email")' to the JS command. Where 'Email' is the placeholder text. Now working as intended.

Upvotes: 2

Related Questions