How could I add / remove required attribute from the textfields depending on a < select > option?

Example: if option 3 is selectd make all fields `required`. Else make only `field1` & `fieldX` required?

html

```
<form id=section3Form>
     <input type="text" id="field1">
     <input type="text" id="field2">
     <input type="text" id="field3">
     <input type="text" id="field4">
     <select id="fieldP" required>
        <option value="option1">Option 1</option>
        <option value="option2">Option 2</option>
        <option value="option3">Option 1</option>
     </select>

     <button type="submit" id="submitBtn" value"Submit">
</form>

```

jQ:

```
$(#submitBtn).click(function(){
  if ($('#fieldP').val() == "option3") {
      //all fields are required
} else {
     //field1` & `fieldX are required.
}
});

```