Hi,
I am using knockout js for my textbox.
I have added a keydown event which calls a javascript function.
The javascript function works, however, the problem I am facing is I cant actually type any text in the textbox because of this keydown event.
I have checked and I can type text in a textbox with uses this javascript method, that is not knockout js bound.
Please can someone explain to me why this and what the difference is and how I can over come this?
I have been struggling with this problem for a very long time now and help on it would be very much appreciated.
The following is my code.
Thank you very much
function keypressdown() {
var event = window.event;
var keyCode = event.keyCode || event.which,
arrow = { left: 37, up: 38, right: 39, down: 40 };
if (event.ctrlKey) {
switch (keyCode) {
case arrow.left:
alert('ctrl + left');
break;
case arrow.right:
alert('ctrl + right');
break;
case arrow.up:
alert('ctrl + up');
break;
case arrow.down:
alert('ctrl + down');
break;
}
}
}
<input type="text" data-bind="value: MyValue,
event: { keydown: function(data, event) { keypressdown() } },
attr: { name: 'MyForm['+$index()+'].MyValue',
id: 'MyForm_'+$index()+'_MyValue'}" />