xingda1213
New Member
I'm creating a simple form with validation, and want any empty input or textarea to have a class added, but I do not know how to check for empty inputs. Currently, it adds to all inputs; I just want the empty inputs/textareas. Help please?\[code\] <form id="contactform"> <input type="text" id="name" placeholder="name" autofocus > <input placeholder="email" > <textarea placeholder="message" ></textarea> <input type="submit"> </input> </form>$(function () { $("#contactform").submit(function () { if($("input, textarea").val() === ""){ $("input").addClass("error"); return false; } $("input").removeClass("error"); });});\[/code\]