开发者

Ajax : Form question

I have a form saying create account and I have email Id and password fields, I want to make sure that the username is unique

is there anyway that I can do this check using ajax as soon as user completes entering开发者_运维百科 the username i.e. after he clicks on the password field (or he hits tab key after entering the username)

Thanks Any efforts will be appreciated


use "onchange" on the username field, then use a standard AJAX query.

What is the difference between onBlur and onChange attribute in HTML?


You can use a (jQuery) .blur() or (standard JS) .onBlur() event on the username field to trigger an AJAX call so you can immediately check whether or not the username is in the database when the user leaves the textfield.


The only thing about the onchange is when does it fire and how does that work across the browsers. I would probably go with onblur to make sure that the user is actually done with field. If the onchange happens each time the keypress event is done, you could end up with a lot of extraneous ajax calls that could bog down the system. Again, onblur would be my choice.


You could:

  1. bind a focus event to the username field
  2. then in this function check if the username has been input
  3. if it is use the AJAX method to send the username across to the server to check
  4. receive a response from the server side for the AJAX request and respond appropriately on the front end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜