jquery highlight input boxes when credentials are wrong when logging in to website

I'm not sure why I can't get this to function correctly like in my jsfiddle:

http://jsfiddle.net/uRvF6/

Perhaps it's because my post action is directing to another page? Maybe it's actually working but because of the url change i'm not seeing it?

<script> 


$('#loginForm').submit(function(){
     var vals = $('.nomargin').val()
     if (!vals) 
        {
          console.log('Error exists');
          $('.nomargin').attr('style', "border-radius: 5px; border:#FF0000 1px solid;");
          $('.nomargin').val('enter a value');
        }  
    return false;
});        
</script> 

        <div class="loginBox clearMeFocus">
                <form action="client_homepage.dhtml" method="post" name="loginForm" id="loginForm" >

<input type="hidden" name="site" id="site" value="free">

                    <h3>Agent Log In</h3>
                    <div style="float: left; font-size: 10px; color: red; margin-top: -8px; position: absolute;"></div>
                    <div class="clearfix">
                        <input type="text" name="username" id="username" value="" title="username" class="nomargin">
                        <input type="password" name="password" id="password" value="" title="password">
                        <input type="image" src="images/submit.png" value="submit" name="submit" id="submit" alt="submit">
                    </div>
                    <h6><a href="/join.dhtml">Not an Associate?</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="/password.html">Forgot Password?</a></h6>
                </form>
            </div>

Any help would be greatly appreciated. Thank you.

Answers


You are returning false outside the condition, so the form will never be submitted, update it as follows:

$('#loginForm').submit(function(){
 var vals = $('.nomargin').val()
 if (!vals || vals=="") 
    {
      console.log('Error exists');
      $('.nomargin').attr('style', "border-radius: 5px; border:#FF0000 1px solid;");
      $('.nomargin').val('enter a value');
        return false;
    }  
});    

check this FIDDLE


$('#submit_form').submit(function(){
     var vals = $('.validate').val()
     if (vals == '') //changed this from !val to == ''
        {
          console.log('Error exists');
          $('.validate').attr('style', "border-radius: 5px; border:#FF0000 1px solid;");
          $('.validate').val('enter a value');
        }  
    return false;
});

Need Your Help

RewritCond. Too many internal redirects. LimitInternalRecursion.

.htaccess redirect mod-rewrite url-rewriting

This code behaves different deppending the order of the conditions:

Command/option + tap a swift function to bring me to the swift source code from objective c

ios objective-c xcode swift hotkeys

In XCode 7.2.1, when working in swift code, I can command tap a function and it will bring me directly to the swift source code where that func is declared.