This post is about 'required' inputs not working in buttons with type 'button'.
I have a form that looks something like this:
<form action="submit.php" method="post">
<label for="username">Start Date</label>
<input id="username" name="inputUsername" type="text" required>
<button type="submit">Submit</button>
<button type="button" onclick="updateUsername()">Update</button>
</form>
When the user clicks on Submit, the form runs the script, submit.php.
When the user clicks on Update, there's an AJAX call for a different script, update.php.
These scripts all run fine except that if you click on the Update button when the text input is empty, it goes through anyways without alerting the user with "Please fill out this field." even though it is 'required'.
I know that the reason this is happening is because its type is button and not submit. However, I can not have two submit types because if I have something like the following:
<form action="submit.php" method="post">
...
<button type="submit">Submit</button>
<button type="submit" onclick="updateUsername()">Update</button>
</form>
It will run the submit.php script AND my other script update.php in my JavaScript function updateUsername() when I ONLY want it to run update.php.
Thanks for any suggestions.