I am trying to add a “check availability” option for the username in my register form.
I have tried using the button tag, but my HTML5 validation prevents the code from being run. Here’s my form, oversimplified:
<input type='text' required>
<!-- The button !-->
<button onclick='isAvailable()'>Check Availability </button>
<input type='password' required>
<input type='email' required>
If the user does not enter a username, password, and (valid) email, then the browser returns an error when the button is clicked.
I have tried using a link instead, but I don’t know how to run my PHP code through it. Can anybody help?
Add a
return false;to the onclick event.And use an Ajax call for the
isAvailable()function to check the availability.