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

    Stop Form Submit

    I have this code. If the user is invalid, it should not echo hello. But why it still show hello after submit?
    PHP Code:
              name: $("#user").val()
                 alert("Data: " + data + "\nStatus: " + status);
                       alert("Invalid User"  );
                    $("form").submit(function (e) {
       var validationFailed = false;
       // do your validation here ...
       if (validationFailed) {
          return false;


    Last edited by VIPStephan; Jan 17th, 2017 at 10:42 PM. Reason: changed quote to code BB tags

  2. #2
    Senior Coder deathshadow's Avatar
    Join Date
    Feb 2016
    Keene, NH
    Thanked 503 Times in 491 Posts
    Uhm, is that last bit of PHP a separate file or something? I mean, you're slopping out scripting (in the head) that won't run until it's client side, so how is this even going to work?

    Much less JavaScript to handle a login?

    What's the form look like? What does the script that actually handles the login look like? You're showing us front-end without the back-end that would actually have the functionality in it...

    ... and really what you are showing reminds me of something a dearly departed friend used to say -- if you can't make it work without JavaScript first, you shouldn't be adding JavaScript to it. I would double that for the bloated train wreck laundry list of how NOT to code JavaScript that is jQuery.
    “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.” – C.A.R. Hoare, The 1980 ACM Turing Award Lecture


Tags for this Thread

Posting Permissions

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