I’m working on a prototype and I want to trigger an action after a submit but only if the required fields were filled.
I have this code
And also an input on my form using the ‘required’ attribute from HTML 5, like this
I want to trigger the action onclick only if the input was filled. I suppose I could do this by checking if the input was filled using jQuery, I was wondering if there is a simpler way
Well, I have actually found a solution, if anyone is going through the same problem, this is how I did it.
Instead of using “onclick” on the button tag I added an “onsubmit” (I had no clue this existed) event inside my form tag with my doSomething function, like this:
The function will only be called if the required inputs are filled, easy as that.
Thanks for the ones who tried to help anyway