Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run a javascript function when input changes

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

I tried :

<input type="text" onkeyup="check_user(this.value)"/>
like image 273
mamrezo Avatar asked Feb 03 '11 12:02

mamrezo


People also ask

What event handler should be used to invoke a function on change of text in input field?

Try oninput : Unlike oninput , the onchange event handler is not necessarily called for each alteration to an element's value. Please Note: You also should not use function keyword as your function name.

How do you trigger an event when a textbox is filled with value?

change function , but that needs to be done only if the the value is changed using the button . $("#address"). change will trigger if you perform any change in text field. If you want to trigger alert only when button click why you don't use alert inside button click function.

Is there an input function in JavaScript?

In JavaScript, we use the prompt() function to ask the user for input. As a parameter, we input the text we want to display to the user. Once the user presses “ok,” the input value is returned. We typically store user input in a variable so that we can use the information in our program.


1 Answers

Call the function on the change event of text field:

<input name="username" onChange="check_user(this.value);" type="text"/>
like image 116
Awais Qarni Avatar answered Oct 14 '22 13:10

Awais Qarni