Bilal Ahmed
Bilal Ahmed

Reputation: 1

Call onClick from JavaScript function

I have created a Live Search that displays results in a table row. Row has onClick function that executes a process of selecting result. OnClick function works fine by mouse click but I want user can select it by up/down arrow key and Enter too. Now I want function set in onClick is called from other JavaScript function. Any help please......

Upvotes: 0

Views: 4171

Answers (2)

Paul
Paul

Reputation: 21

myElement.onclick = function() {
    // called when myElement is clicked
}

or just

myElement.click(); // clicks the element

And use an onkeydown event to call it, and just check for characters before the click();

myField.onkeydown = function() {
    myElement.click();
}

Upvotes: 2

DrStrangeLove
DrStrangeLove

Reputation: 11587

try something like this:

$('tr').live({
      click:  function(e)
    {       
        //your code here;
    },
      keyup: function(e)
        {
              // and here;
        }
   })   

it requires jQuery

Upvotes: 0

Related Questions