Trying to add a "check availability" option to my register form
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 anyb开发者_高级运维ody help?
Add a return false;
to the onclick event.
<button onclick='isAvailable(); return false;'>Check Availability</button>
And use an Ajax call for the isAvailable()
function to check the availability.
Try to use jQuery library. You can use this: http://api.jquery.com/jQuery.get/ to get return from your url: http://example.com/checknick.php?&nick=...
精彩评论