...

View Full Version : Javascript ignoring my code? Is this real life?



Keysle
11-22-2010, 03:07 AM
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.:mad::mad::mad:
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.
:mad:


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

DrDOS
11-22-2010, 03:36 AM
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.

Old Pedant
11-22-2010, 04:26 AM
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:


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.

Keysle
11-22-2010, 04:57 AM
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.

Old Pedant
11-22-2010, 05:11 AM
Hmmm...Chrome may be more forgiving, like MSIE. Dunno.

But as I said, the logic is all wrong, anyway.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum