I am using the following javascript function which detects whether ctrl + any of the arrows keys has been pressed.
This works, however I am facing a problem where by I can't actually type in any text in the textbox.
Does anyone know why this might be and what I can do to over come this?
Is it because this function is called on every keydown press?
Any help would be much appreciated as I have been struggling with this for a long time.
Thank you very much
function keydownpress(data, event) {
event = 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;
}
}
}
Thank you for your reply, even without the alerts, I still cannot type any actual text in the textbox which calls this function with the onkeydown event.
Please can you offer advise on how I can fix this issue?
young345
Member
201 Points
720 Posts
Why cant I type any text in the textbox?
Jan 24, 2013 12:21 PM|LINK
Hi,
I am using the following javascript function which detects whether ctrl + any of the arrows keys has been pressed.
This works, however I am facing a problem where by I can't actually type in any text in the textbox.
Does anyone know why this might be and what I can do to over come this?
Is it because this function is called on every keydown press?
Any help would be much appreciated as I have been struggling with this for a long time.
Thank you very much
function keydownpress(data, event) { event = 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; } } }raju dasa
Star
14396 Points
2449 Posts
Re: Why cant I type any text in the textbox?
Jan 24, 2013 12:36 PM|LINK
Hi,
alert() method blurs the focus off the textbox,
try console.log() instead of alert()
and check the results in console.
rajudasa.blogspot.com || blog@opera
young345
Member
201 Points
720 Posts
Re: Why cant I type any text in the textbox?
Jan 24, 2013 12:45 PM|LINK
Hi,
Thank you for your reply, even without the alerts, I still cannot type any actual text in the textbox which calls this function with the onkeydown event.
Please can you offer advise on how I can fix this issue?
Thank you
teddy_q
Member
712 Points
139 Posts
Re: Why cant I type any text in the textbox?
Jan 25, 2013 05:41 PM|LINK
I don't see anything in the code that would prevent the typing. Are you sure the text box doesn't have the attribute ReadOnly = true?
young345
Member
201 Points
720 Posts
Re: Why cant I type any text in the textbox?
Jan 27, 2013 04:53 PM|LINK
thanks for your reply.
my textbox is knockout js bound and by default when it uses an event property it prevents default behaviour.
i managed to fix my code by returning true after the event, which allowed me to type text in.