JavaScript Tutorials
JavaScriptKeyboard Handling in JavaScript
The interaction of hardware in JavaScript and Ajax based applications have often been focused on mouse especially on its hover function. This is understandable since in an effort to build a highly effective application, the developer has to provide as much information and assistance as it can to its users. The hover function in mouse could prompt the server to provide information or even execute a certain command without a single click. This feature is often used for drop-down windows and boxes.
On the other hand, the interaction of the keyboard with Ajax and/or JavaScript applications has been ignored. The reason for this is basically on the fact that the mouse has become the sole explorer of the functions in most Ajax based applications. When information is needed to be keyed in, the user still has to send the cursor to the box before any action from the keyboard could be expected. Depending on the configuration of the developer, the user can’t easily use the tab function to navigate from one command to another.
If the developer wishes to increase interaction, he or she should implement keyboard handler. This is a specific set of commands that could easily interact with a keyboard.
The command in JavaScript to properly interact with the application goes this way:
focus/onfocus
This is a very simple command that could be used by the mouse as well when interacting with the application. If the developer wishes to create an Ajax or JavaScript application with a keyboard, this should be part of the function.
The following are the only functions that could be used with a keyboard:
• links
• form field
• location bar
One of the biggest advantages in using JavaScript for keyboard handling is the ability to read and interact to CSS. When properly coded, CSS could be easily loaded in functions that could use a keyboard handler.
Alternative for HTML
Another reason why developers tend to ignore keyboard handling is the interaction of HTML with JavaScript to build an Ajax based application. The presence of HTML will naturally ease the interaction with the keyboard as HTML could be hovered or focused with the use of a simple tab. If an HTML is present in an Ajax based application, developers would just go for functions in HTML to be hovered with keyboard and use the mouse for other functions.
On the other hand, developers could combine the functionality of HTML with JavaScript for keyboard handling. But this is rather a difficult task that if you are building a small application, it’s better to build JavaScript for mouse interaction and keep the keyboard in HTML.
Ultimately, keyboard handling in JavaScript is a possibility as long as the developer uses :focus/onfocus function. Although the usability of keyboard handlers is very limited, this should be implemented if the developer wants to have an interaction application. There is also an alternative (and recommended) method in HTML if they want to build an application with a more extensive interaction with keyboards. Combining them is a possibility but a challenge for small Ajax based applications.
Sponsored Links
