开发者

return false in if statement not recognized in IE - Jquery

The following code checks to see if user entered their email address & password.

This works great in Firefox/Chrome, but I'm having issues in IE. In IE, when you don't enter your user name and password, it turns the boxes red (as expected), and also doesn't change the text to 'Loading...', so it goes to the return false in the last else statement, but IE doesn't recognize it for some reason—is there a work around I should know about?

$('#gettheiremail').submit( function() { 
    var passwordinfo = $('#passwordtextbox').val();
    if ($('#signuptextbox').attr('value') == '' || $('#signuptextbox').attr('value开发者_JS百科') == 'Your Email Address' ) {
        $('#signuptextbox').css('color','red');
        $('#signuptextbox').css('border','3px solid #ff0000');
    }
    if ($('#passwordtextbox').attr('value') == '') {
        $('#fakepassword').css('color','red');
        $('#fakepassword').css('border','3px solid #ff0000');
        $('#passwordtextbox').css('border','3px solid #ff00000');
    }
    if((!($('#signuptextbox').attr('value') == '' || $('#signuptextbox').attr('value') == 'Your Email Address' )) && $('#passwordtextbox').attr('value') != '' )
    {
        $('#sendform').val('Loading...');       
    }
    else
    {
        return false;       
    }
});

Here's the working code after fixes

$('#gettheiremail').submit( function(e) { 
    var signuptextbox = $('#signuptextbox').attr('value');
    if (signuptextbox == 'Your Email Address' ) {
        $('#signuptextbox').css('color','red');
        $('#signuptextbox').css('border','3px solid #ff0000');
        e.preventDefault();     
    }
    var passwordtextbox = $('#passwordtextbox').attr('value');
      if (passwordtextbox == '' || passwordtextbox == 'Enter Your Email Password') {
        $('#fakepassword').css('color','red');
        $('#fakepassword').css('border','3px solid #ff0000');
        $('#passwordtextbox').css('border','3px solid #ff00000');
        e.preventDefault();
    }
    if(!((passwordtextbox == '' || passwordtextbox == 'Enter Your Email Password') && (signuptextbox == 'Your Email Address')))
    {
            $('#sendform').val('Loading...');           

    }

});


Have you tried:

$('#gettheiremail').submit(function(e) { 
   /* Other code */
   e.preventDefault();
   /* Other code */
});


If neither of the two things at the end of your code are happening, then the odds are that you're never reaching the end of that code — e.g., that an exception is being thrown in the middle. You'll want to walk through with a debugger (you can use the built-in stuff in IE8+, or VS.Net [there's a free edition] for earlier versions).


Off-topic: You're reiterating a lot of lookups:

if ($('#signuptextbox').attr('value') == '' || $('#signuptextbox').attr('value') == ' ...

Every time you write $('#xyz') it triggers several function calls, at least one memory allocation, and causes a DOM lookup (which is not necessarily all that fast, even when looking up by id). Similarly, constantly calling attr again for the same attribute is more unnecessary overhead (though not nearly so much). Instead:

var signuptextbox = $('#signuptextbox'),
    signupvalue   = signupvalue = signuptextbox.attr('value');
if (signupvalue == '' || signupvalue == '...

(Or don't keep the signuptextbox if you just need its value.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜