# Make field required if checkbox checked

**URL:** <https://community.gravityforms.com/t/make-field-required-if-checkbox-checked/13437>\
**Category:** Get Help\
**Tags:** gform\_field\_validation, gform\_pre\_validation\
**Created:** [September 14, 2022, 1:18am UTC](https://community.gravityforms.com/t/make-field-required-if-checkbox-checked/13437 "2022-09-14T01:18:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mareider](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/mareider/32/2723_2.png) [@mareider](https://community.gravityforms.com/u/mareider)\
**Post date:** [September 14, 2022, 1:18am UTC](https://community.gravityforms.com/t/make-field-required-if-checkbox-checked/13437/1 "2022-09-14T01:18:35Z")

</div>

How does GF build the logic to determine if a field is required or not? I am trying to create it so when a checkbox option is checked other fields within the form become required. I created some javascript which adds a required attribute, but my form still submits.

```auto

$(document).ready(function() {
	$('#choice_3_7_2').on("change", function() {
		if (($(this).prop('checked'))) {
				$("#field_3_8").attr('required', ($(this).attr('required') == "required" ? "" : "required"));
			}
	});
});

```

Any help would be appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [September 14, 2022, 3:43am UTC](https://community.gravityforms.com/t/make-field-required-if-checkbox-checked/13437/2 "2022-09-14T03:43:08Z")

</div>

Hi Mareider. Take a look at this example which uses the `gform_pre_validation` filter:

> **[gform\_pre\_validation](https://docs.gravityforms.com/gform_pre_validation/#1-conditionally-required-field)**
>
> This filter can be used to manipulate the Form Object used during the form validation process.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/gravityforms1/original/2X/f/fef63f0599c45e0218c30d9f5d7ca8bff9b00189.png) [@system](https://community.gravityforms.com/u/system)\
**Post date:** [October 14, 2022, 3:43am UTC](https://community.gravityforms.com/t/make-field-required-if-checkbox-checked/13437/3 "2022-10-14T03:43:31Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
