Skip to content
Advertisement

Switching required input fields validate dynamically

I have a form with 2 buttons (Save Draft and Save Final FORM).
I would like to switch the required fields depending on which button pressed.
When I push the Save Draft it’s required to fill out only the Name’s field.
When I push the Save Final FORM it’s required to fill all of the fields except Text field.

How can I do that?

HTML:

JavaScript

Thanks 😉

JSFIDDLE

Advertisement

Answer

Just add a click eventlistener to your buttons.

Add this at the END of your file before closing </body> tag. I’ve only given you an example of the first button. You should be able to reproduce this however you want for the other button.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement