5
Bubbles
6y

Okay so I'm pissed. My JavaScript form validation doesnt work so I went tried it on the most simple fucking html form and it fucking works and I dont fuckign know what the problem is since I literally copy and pasted the form from the one that doesnt work

Comments
  • 2
    You wanna show us the two forms?
  • 1
    @growling I can if needed I was just ranting.

    Update: I transferred the div code over to the one that works and it broke it somehow. So I have no idea what to do
  • 1
    @growling
    The Broken/copy of original:
    https://pastebin.com/L2BsmJ8L

    the simple fucking retarded working one:
    https://pastebin.com/FN0uGVQa

    idk how people usually share code aside github but I just use paste bin apologies for any future problems
  • 1
    also if its needed heres the php that works okay:
    https://pastebin.com/aBNPxn6d

    heres the javascript:
    https://pastebin.com/PAp03JWa
  • 1
    Put onsubmit="return validate_login()"

    You’re missing a return
  • 1
    @growling I'll end my career that hasnt started if you are right
  • 1
    @growling it worked holy shit thank you. Can you explain why I need return I dont really understand
  • 2
    @Bubbles in your validator code, it returns true or false yes? If you return false onsubmit, you won’t be able to continue posting your form. However if it’s true, you continue. Therefore, when you had no return, the form didn’t really know what to do
  • 1
    Yeah your code will return undefined implitly since you are not returning anything. The return value is compared exactly (===) to false here, so undefined will not stop the form from submitting (the default behavior).

    The more modern way to handle it would be to take the event as an input in your validator function and then call event.preventDefault() if the input is not valid.
  • 0
    @growling oh I understand that makes sense
Add Comment