I neeed to fill in an input box using keyboard events 'keydown' 'keypress' and 'keyup' for running some test cases .I tried with following code
var fireKeyEvent = function(eventType,element,keyCode) {
var keyboardEvent = jQuery.Event(eventType);
keyboardEvent.which = keyCode;
keyboardEvent.keyCode = keyCode;
$(element).trigger(keyboardEvent);
}
i have the following html element
<input type='text' id='input'>
i tried firing following
fireKeyEvent('keydown',$('#input'),49);
fireKeyEvent('keypress',$('#input'),49);
fireKeyEvent('keyup',$('#input'),49);
where 49 is the ascii code of 1 so it should insert 1 into the text box. But it doesnt seem to insert anything into the text box.can someone help?