1

How do i create and pass the event to event handler?

Basically i want to fire an event called key down on focus of text input box how do i do that?

3
  • Perhaps firing keydown isn't what you want - it won't cause a letter to be inserted. Commented Apr 22, 2011 at 10:04
  • there are already onkeydown, change events. What exact is your scenario? Commented Apr 22, 2011 at 10:05
  • @Box9 & @nEEbz you can look at answer given by me which fits into my requirement, thank you for support. Commented Apr 22, 2011 at 11:14

3 Answers 3

1

This probably blog entry should help you.

<input type="text" onchange="alert('i was clicked')" id="test">
<script>
    document.getElementById("test").onchange()
</script>
Sign up to request clarification or add additional context in comments.

Comments

1

Use this if you actually want to trigger the event programmatically:

function eventFire(el, etype){
  if (el.fireEvent) {
   (el.fireEvent('on' + etype));
  } else {
    var evObj = document.createEvent('Events');
    evObj.initEvent(etype, true, false);
    el.dispatchEvent(evObj);
  }
}

Comments

1

Here is what i found which meets my requirement using Jquery.

$('#inputText').focus(function() {
         $('#inputText').trigger({type:'keyup',keyCode:'40'});
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.