How can I run javascript function when input changes

When a user creates a new account on my website, I want to check if this name exists. I want this check to be performed when they leave the username input field and go to enter the password.

I tried:

<input type="text" onkeyup="check_user(this.value)"/>
+5
source share
4 answers

You need to use the onblur event. It fires when the control loses focus, which seems to be exactly what you need.

+7
source

Call a function in a changetext field event :

<input name="username" onChange="check_user(this.value);" type="text"/>
+7
source

Since you used onkeyupcode in your example code, it sounds as if you want to call a function every time you press a key. If so, instead of onchange- which fires when it inputloses focus, you should use oninputone that will fire anytime there is a change inside the input.

+2
source

I think you're looking for user duplication checking. for this you need to write server-side code.

+1
source

All Articles