0

Recently I decided to learn Javascript and have been trying to create a script that will put a border around empty elements before the form is submitted. Essentially I want the form to be live validation and notify the user before they click submit. Any help would be greatly appreciated.

5
  • 1
    You should share some code you've tried.
    – ZiNNED
    Jun 18, 2014 at 13:25
  • The only code I've tried is simple getElementById nothing too advanced because I've only been doing js about a month. Jun 18, 2014 at 13:26
  • yep @ZiNNED. But just to get you rolling, you would do something like if(form.box1.isEmpty()) form.box1.addClass('empty-form'); Jun 18, 2014 at 13:27
  • would form.box1.empty() be live? or would I have to submit the form? Jun 18, 2014 at 13:29
  • It's just pseudocode. You would probably want to have a javascript watcher on your form. Jun 18, 2014 at 13:31

1 Answer 1

0

There are very many plugins if you want to use jQuery as your title suggests:

http://www.jquerybyexample.net/2014/05/15-useful-jquery-validation-plugins.html

Just pick whatever you want :-)


Or if you want to use plain JS, just search "javascript form validation" on google, you'll find thousands of entries, e.g. http://www.learn-javascript-tutorial.com/javascript-form-validation.cfm and http://www.tizag.com/javascriptT/javascriptform.php

11
  • Thanks for this, but, would you be able to give me any advice on how this works? I want to learn more about js/jquery but am having a hard time based off the code snippets offline. Jun 18, 2014 at 13:27
  • Sure if you'd ask a specific question about a certain piece of code!? I can't explain you something, when you don't provide me an example to be explained.
    – tim
    Jun 18, 2014 at 13:28
  • 1
    @mplungjan: It's good enough for a real beginner.
    – tim
    Jun 18, 2014 at 13:29
  • Would running a setInterval to run a function work to check form fields? Jun 18, 2014 at 13:29
  • 1
    Yes - annoyed users. Instead use the keyup event handler on the fields as they are focussed
    – mplungjan
    Jun 18, 2014 at 13:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.