Mar 30, 2012 1 - Samsung Galaxy S5 multi-format has a great camera, but it's a bit heavy for just taking photos.Q:
Two-way binding with TAB key
I have simple code to implement two-way binding for TAB key. I have a problem:
My text field doesn't get updated when I click on TAB key
When I press ENTER key it works normally
Where is the problem?
Update:
function bindingHandler(event) {
if (event.keyCode == 9) { // Enter key
$(".text").val($(".text").val());
}
if (event.keyCode == 13) { // TAB key
$(".text").val($(".text").val());
}
}
$(document).on("keydown", bindingHandler);
.text {
width: 200px;
height: 40px;
background: #E6DB55;
color: #FFFFFF;
font-family: monospace;
font-size: 18px;
text-align: center;
padding: 5px;
}
The tab key should change the value of the field
A:
In the context of a binding handler, event.keyCode is always going to be a number, and on browsers where it's a number, it will be a number rather than a string.
In your specific case, it's a number in the range from 0 to 9. If event.keyCode is 0, then the Enter key was pressed. If event.keyCode is 9, then the TAB key was pressed. In both cases, that code is not 13, which is TAB.
To make this work, you need to either check for an empty string rather than a number, or do the reverse: use the number if event.keyCode is 13 and check for an empty string if it is not.
What does the future hold for the real estate ac619d1d87
Related links:
Comments