View Single Post
Old 12-20-2012, 11:04 PM   PM User | #8
LearningCoder
Regular Coder

 
LearningCoder's Avatar
 
Join Date: Jan 2011
Location: The Pleiades
Posts: 848
Thanks: 67
Thanked 28 Times in 28 Posts
LearningCoder is an unknown quantity at this point
Quote:
Originally Posted by Old Pedant View Post
Ummm...there's no such thing as "switching".

jQuery *IS* JavaScript. So there's no "switch" to be made.

Having said that.. If the only reason you will use jQuery on the page is for this one AJAX call... Why? AJAX can be done in just a few lines of vanilla JavaScript. Why drag in the entire jQuery library for something so simple?
I didn't realize it was as easy as you say because my JS book tells me that I have to check for ActiveXObjects or something then do two different things depending on what it returns. I thought it would be a lot easier with jQ.

Quote:
Originally Posted by OldPedant
Oh, and in any case, your email test is virtually worthless. I could type in .@@@@@@.... and your code would be perfectly happy.

Email validation has been discussed in this forum dozens if not hundreds of times. Do a simple search in the forum for *good* examples.
I know it isn't the best but I just wanted to add at least some js validation to prevent a certain submit to the server. It's a real difficult subject if you aren't familiar with RegExps. I'm not too worried though because if it does pass my JS validation, I have some PHP email validation which should catch it.

Quote:
Originally Posted by OldPedant
Also, your method of telling the user about errors is really bad.

You go to all the trouble of creating an array of errors, but then you *STILL* output the errors via alert( ) one at a time!

At the very least you could do:
Code:
    if(count != 0)
    {
        alert( "Please correct:\n" + error.join("\n") );
        return false;
    }
    // there is NO POINT in having an else here!  the return means "return right now!"
    return true;
However, as many here will be happy to tell you, alert( ) is very badly out of style. Some browsers allow users to turn off ALL alerts. And likely most all browsers will do so soon.
Thank you very much that seems a much better way rather than alerting one at a time. If alert() is old and not used to much anymore, what is the other alternative? Do you just innerHTML anything you need to directly to the page? Is there a new way to show an alert() or should we not be using any alert type messages altogether?

Quote:
Originally Posted by OldPedant
p.s. There's also no need for your count variable.

Code:
    if ( ...something fails validation... )
    {
        error.push( "...the error message..." );
    }
    ...
    if ( error.length == 0 ) return true;
 
    document.getElementById("somePlaceToShowErrors").innerHTML = error.join("<br/>");
    return false;
Thank you very much, I think that code just answered my question above! I'll start editing the code as soon as I can sort my other issue out. Can't get onto my contact page because it connects to mysql and it doesn't seem to be loaded as an extension in my version of php :s I've got mysqlnd?

Nevertheless thank you indeedy.

Regards,

Lc.
LearningCoder is offline   Reply With Quote