Questions
Questions

Reputation: 20875

Mouse & keyboard event names in JavaScript

I want to ask a question about the JavaScript event. I have an <input type="text"> box and I have applied the autocomplete function on that box.

I know that when the user types the char like "sta" in the box and the JavaScript will call the keypress event, which also calls the autocomplete function.

However, I want to know what event of the JavaScript will be called what I use the mouse to click/click the keyboard "enter" to the wanted item from the autocomplete list.

Upvotes: 0

Views: 790

Answers (2)

Sarfraz
Sarfraz

Reputation: 382696

However, I want to know what event of the JavaScript will be called what I use the mouse to click/click the keyboard "enter" to the wanted item from the autocomplete list.

It sounds like you are looking for an event which triggers after text of the text box changes. If that is the case, the event fired is onchange.

That will take care if user select autocomplete option either via mouse or hits the enter button.

Upvotes: 1

Harmen
Harmen

Reputation: 22438

The mouse clicking event is called onclick, the enter key event is called an onkeyup event. For the second one, you need to make sure the enter key was pressed, though:

someElement.onkeyup = function( e ){
  var e = e || window.event;

  if( e.keyCode == 13 ){
    // enter was pressed!
  }
};

Upvotes: 1

Related Questions