I've got a performance problem in IE. I'm working on a hotkey function and instead of using TAB and SHIFT+TAB the user will be able to use 4 buttons to go up/down/left/right.
When going left or right I fetch all elements in the form, searches for the selected field (I get it from the event) and selects the field with the lesser index of form.elements if the user presses left etc.
This works great but the problem is that I got many elements so the system isn't responsive enough when its in the middle of the form.
Is there a way to get the index in form.elements of the field of the event instead of searching for it? I can't use a tabindex as many elements are created dynamicly.
Here is a simplified version of my code:
When going left or right I fetch all elements in the form, searches for the selected field (I get it from the event) and selects the field with the lesser index of form.elements if the user presses left etc.
This works great but the problem is that I got many elements so the system isn't responsive enough when its in the middle of the form.
Is there a way to get the index in form.elements of the field of the event instead of searching for it? I can't use a tabindex as many elements are created dynamicly.
Here is a simplified version of my code:
Code:
var bookingForm = document.getElementById("bookingForm");
for (var elementIndex = 0; elementIndex < bookingForm.length; elementIndex++) {
if (bookingForm.elements[elementIndex] == target) {
var indexNavigation = 0;
if (key == 100) { //if the left button was pressed
indexNavigation = -1;
}
else if (key == 102) { //if the right button was pressed
indexNavigation = 1
}
var nextElementIndex = elementIndex + indexNavigation;
var nextElement = bookingForm.elements[nextElementIndex];
...
}