0

I am bit confuse on this Javascript function

When to use return false or event.preventdefault() ?

I'm working on my first web app, and I want user to completely enter the required input in my forms

I have read some article about this, googling, surfing everywhere, some says return false, and other side says event.preventdefault()

ex if (InputA == '' || inputA == 0) {event.preventdefault()}

or if (InputA == '' || inputA == 0) {return false}

What is the different ? Is this will completely stop the form from submitting inputed value to DB ?

Any help will be appreciated

Thanks !

Gwein
  • 23
  • 7
  • Thank you sir, and what do we do as web dev after this javascript function ? Should we show some error notification in forms ? with css n text ? Or we refresh the page ? I am really got confused here (@_@") – Gwein Nov 15 '18 at 11:38
  • and 1 other point, I used disabled prop HTML properties in my forms ex if a true, prop disabled else prop false is that okay ?? – Gwein Nov 15 '18 at 11:40
  • You should show errors regarding the missing data in that form. – ElusiveCoder Nov 15 '18 at 11:40
  • You should not just scatter `return false`s and `e.preventDefault()`s all over your script. You use them when there's a need to use them. And when there will be a need, you'll also know what to do afterwards, – Teemu Nov 15 '18 at 11:41
  • I use this `disabled="false"` so if the user already complete the requirement, my jquery code will `disabled="true"` is that okay ?? – Gwein Nov 15 '18 at 11:45
  • Please ask a more specific question, as it is, it's hard to say what exactly you're needing, perhaps a full tutorial of DOM events, functions, and form validation, which all are more or less separated features. – Teemu Nov 15 '18 at 11:51
  • i found my answer here [using-jquery-preventing-form-from-submitting](https://stackoverflow.com/questions/9347282/using-jquery-preventing-form-from-submitting) – Gwein Nov 15 '18 at 12:24
  • thank you all for viewing my post and tried to help me, I really really appreciate you all big thanks ! – Gwein Nov 15 '18 at 12:27

0 Answers0