I'm building a form system with jquery and using basic validation (if a form has the required values and is of the required type) as a front line system (I validate at the backend too) for validating as the user submits, this is to prevent useless requests when possible (eg: submitted a completely empty form)
What is the "proper" way to handle this? My default idea is to apply a class to the elements, like so:
<input type="text" name="something" class="required">
or
<input type="text" name="something" class="optional">
and then simply looping through and checking if the classes match, is this an "okay" way to do it or is there a better way? I could apply custom attributes but I'd feel bad and I don't know if all browsers support this.
Note: These fields aren't necessarily the same every time, hard coding into the js isn't a possibility (or imo a good idea).