validation - Check if inputs are empty using jQuery -


I have a form that I would like to fill in all areas. If a field is clicked and is not filled, I would like to display a red background

Here is my code:

  $ ('# apply- Form input '). Blur (function () (if ($ ('' input: text '') (": empty") {$ (this) .parents ('p'). AddClass ('warning');}});   

  $ ('# apply-form input'). Blur (function () {if (! $ (.) () .val ()) {$ (This) .parents ('p') AddClass ('warning');}});  

And you do not need the necessary .length or see if it's & gt; 0 because the empty string treats anyway as wrong, but if you want it for readability purposes:

  $ ('# apply-form input'). Blur (function () {if ($ (this) .val (). Length === 0) {$ (this) .parents ('p') AddClass ('warning');}});  

If you are certain that this will always work on a text field element, then you can only use this.value .

  $ ('#in-apply input'). Blurring (work!) (If (! This.value) {$ (this) .parents ('p') AddClass ('Warning');}});  

with it You should also keep in mind that $ ('input: text') captures multiple elements, specify references or use this if you only use a single element Want reference (Referral children of message / children have a textfield).


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -