I have a form with a several different field types, all of which need to be complete before submission. I have the submit button disabled and would like to remove the disabled attribute once all the fields have values.
I have examples from previous questions of this functionality working with radios and checkboxes and I've read a few answers which show how to achieve this using <input>
fields only:
- Disabling submit button until all fields have values
- Disable submit button until all form inputs have data
But is there any way we can get check that all field types have values using jQuery? Including <select>
and <textarea>
fields?
Here's a Codepen of a basic version of my form and here's my HTML:
<div class="contact-form">
<div class="contact-form__row">
<p>Text field</p>
<input type="text" />
</div>
<div class="contact-form__row">
<p>Radio fields</p>
<label for="radio-1">Radio 1</label>
<input id="radio-1" type="radio" name="radio-option" />
<label for="radio-2">Radio 2</label>
<input id="radio-2" type="radio" name="radio-option" />
</div>
<div class="contact-form__row">
<p>Checkbox fields</p>
<label for="checkbox-1">Checkbox 1</label>
<input id="checkbox-1" type="checkbox" />
<label for="checkbox-2">Checkbox 2</label>
<input id="checkbox-2" type="checkbox" />
</div>
<div class="contact-form__row">
<p>Select options</p>
<select id="my-select" name="my-select">
<option value="a">Option A</option>
<option value="b">Option B</option>
</select>
</div>
<div class="contact-form__row">
<p>Text area</p>
<textarea></textarea>
</div>
<div class="contact-form__row">
<input type="submit" value="Submit" disabled />
</div>
</div>
Is this possible?