I want to know how I can use javascript if the user enters a user name when creating the account Has been present in the database and ask the user to type another user name? jQuery (I'm very lazy Pure JS) + PHP sample code:
Blurring
for & lt; Input / & gt;
element.
& lt; Form ... & gt; ... & lt; Input type = "text" name = "user name" id = "input-user name" /> & Lt; P class = "error" & gt; & Lt; / P & gt; ... $ ("#input-username"). Blur (function {$ .post ("/ check-username.php", {user name: $ (this) .val ()}, function (data) {if ("0" == data) {/ * Username Usage * / $ (this) .next ("p"). Text ("This username is already in use. & Lt; / p & gt;") Other} / * Username is correct / $ ( This) .next ("p") below ();}});}); & Lt ;? Php $ username = $ _POST ['username']; // Check whether the user name database exists in the $ usernameExists = ...; Copy $ usernameExists? '0': '1'; // if present, 1 if not
Comments
Post a Comment