Title: Make a field required in JavaScript
Last modified: January 31, 2025

---

# Make a field required in JavaScript

 *  [juliamb](https://wordpress.org/support/users/juliamb/)
 * (@juliamb)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/make-a-field-required-in-javascript/)
 * Hi!
   I’m trying to change a field inside a form to make it required after the 
   form has been loaded, so I’m doing it in a JS script. I’m adding the _required_
   attribute but when I submit the form, this new required fields isn’t being validated…
   do I need to do something else to make a field required?
 * Thanks in advance
   Regards

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [nate.ads](https://wordpress.org/support/users/nateads/)
 * (@nateads)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/make-a-field-required-in-javascript/#post-18278249)
 * [@juliamb](https://wordpress.org/support/users/juliamb/) I used jQuery to do 
   something slightly similar I think. I used it to disable and enable my submit
   button only after a specific field was filled.
   Not sure if this might help.
 *     ```wp-block-code
       jQuery(document).ready(() => {			jQuery('.wpcf7-submit').attr("disabled", "disabled");			jQuery("input[type=text]").keyup(onFormUpdate);		})				function onFormUpdate() {			const fieldName = jQuery("#field_name").val();						if (fieldName) {				jQuery('.wpcf7-submit').removeAttr("disabled");			} else {				jQuery('.wpcf7-submit').attr("disabled", "disabled");			}		}
       ```
   
 *  Thread Starter [juliamb](https://wordpress.org/support/users/juliamb/)
 * (@juliamb)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/make-a-field-required-in-javascript/#post-18280701)
 * Hi Nate, thank you so much for your answer!
   I will have this solution in mind,
   in case I can’t find the way of properly validate the form. I would need to show
   a message the users when they’re missing some fields.
 * I guess I could add custom validation for the entire form, but I wanted to avoid
   this (is quite a long form).
 * Regards!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Make a field required in JavaScript’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [juliamb](https://wordpress.org/support/users/juliamb/)
 * Last activity: [1 year, 4 months ago](https://wordpress.org/support/topic/make-a-field-required-in-javascript/#post-18280701)
 * Status: not resolved