Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OnChange and OnKeyUp on control

I have an edit box which accepts an email address on my html page.

At the moment, I have a javascript call 'onkeyup' which verifies if the email address is OK.

And it works well while the user types.

However, if I start typing my address (We will use [email protected]), and I start with:

me@

My autocomplete offers me '[email protected]', as I have used it before.

When I select that from the autocomplete drop down - 'onkeyup' doesn't fire. Instead, 'onchange' fires.

I need both to fire. As the suer types, I want to validate (onkeyup), but I need to also fire the javascript 'onchange'. I don't, however, think I should fire both events. Is there a way to handle both with a single event?

like image 731
Craig Avatar asked Sep 05 '25 03:09

Craig


1 Answers

You can use oninput event to combine onkeyup and onchange events. This event fires on pasting (ctrl+v) too.

<input name="title" oninput="func()">
like image 171
Amir Fo Avatar answered Sep 07 '25 22:09

Amir Fo