Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2010
    Posts
    33
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Angry Javascript ignoring my code? Is this real life?

    in the function emailTest in this code I can't seem to get the FIRST if statement to pass even if I put 1 in the in the email.value text box.
    even if i change the if condition to (email.value=="1") or (email.value=="a") and make the email.value text field equal respectively, IT STILL WON'T PASS
    only if I do (1==1) will it work.

    ----some background----
    I was making a javascript form checker and i needed to test if the email field was an email. First I tried using an isEmail function. Didn't work. But the funciton seemed legitimate. I tinkered for hours trying to find glitches (it's simple regular expressions... i mean how hard could I screw it up?) and then eventually made the function return true by default so that the function would do nothing more but return true. Even when the function JUST returned true. (i also tried just returning 1) it still didn't pass. Then I took the function out of the if statement all together and tried the regular expression test in the if function. that didn't work. Now I'm trying to compare the variable directly to something simple. AND IT STILL DOESN'T WORK.
    WHAT is going on here people? REALLY ... I mean REALLLY/!?!? I've been programming for 7 GD years of my GD life (not javascript honestly) and SIMPLE CODE SHOULDN'T FAIL THIS HARD.


    Code:
    function emailTest()
    {
    
    
    if (email.value==1)
    
    {
    
    emailErrorBox.innerHTML="Please insert a valid email";
    
    emailSuccessBox.innerHTML="";
    
    }
    
    
    
    if (email.value.length>0 && email.focus)
    
    {
    
    emailErrorBox.innerHTML="";emailSuccessBox.innerHTML="";
    
    request.abort();
    
    var url = "/unseen/checkIfEmailExist.php?email=" + email.value;
    
    request.open("GET", url, true);
    
    request.onreadystatechange = updateEmailCheck;
    
    request.send(null);
    
    }
    
    if (email.value.length===0)
    
    {emailErrorBox.innerHTML="Please insert an email";emailSuccessBox.innerHTML="";}
    
    
    
    }
    If you go to http://freetexthost.com/dgbgshkzkj that is my code. It's a lot. I can't just give you a portion because I think it's something on the large scope that is screwing me up.


    This entire thing has me furious because IT IS SIMPLE CODE THAT REFUSES TO WORK... LITERAL REFUSAL THE COMPUTER JUST SAID NO NO NO NO.
    I am SERIOUSLY trying to get rolling on this project but some hidden syntax of javascript is blocking me from having these functions work correctly
    Last edited by Keysle; 11-22-2010 at 02:17 AM. Reason: inaccurate code box

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,990
    Thanks
    15
    Thanked 233 Times in 233 Posts
    Try this, replace all email.value with emailval and add this line.

    var emailval = parseInt(email.value);
    if (emailval==1)

    or use parseFloat if email.value may not be an integer.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,519
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    Of course you can't get it to work.

    There is no such thing as email.value.

    There *seems* be such a thing as document.forms[0].email.value.
    And I guess even document.getElementById("sign_up").email.value would work.

    But aside from all that, the function is worthless. And that check is worthless.

    For now, I will assume that you *can* get the email field's value using your code. Heck, it might even work in MSIE, though it won't in other browsers. Anyway:
    Code:
    function emailTest()
    {
        if (email.value==1) // OKAY...let's say the value *IS* 1 !!!
        {
            // so these two statements, changing those two innerHTML's will execute:
            emailErrorBox.innerHTML="Please insert a valid email";
            emailSuccessBox.innerHTML="";
        }
    
        if (email.value.length>0 && email.focus)
        {
            // okay...if the value *was* 1, then the value.length *WILL BE* > 0!!!!
            // and of course you can focus on the field (that's a worthless test),  so...
            //
            // THESE two statements *WILL* execute:
            emailErrorBox.innerHTML="";
            emailSuccessBox.innerHTML="";
        }
    And so you have WIPED OUT the error indication that you tried to put in after the first IF test!!!

    POINTLESS!

    So don't blame JavaScript for trying to follow your flawed directions.

    There are several more mistakes in the code, but no point in going into them because you'll surely be changing all this, anyway.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New Coder
    Join Date
    Nov 2010
    Posts
    33
    Thanks
    12
    Thanked 0 Times in 0 Posts
    The odd this is Old Penant is that "username" refers to a text field and it works just fine in google chrome when I test it's functionality. (I had some other issues and it wasn't working in other browsers)
    the reason may be because of what you were talking about earlier.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,519
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    Hmmm...Chrome may be more forgiving, like MSIE. Dunno.

    But as I said, the logic is all wrong, anyway.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •