I am in the process of developing a form for the company intranet and i've recently added in code to capture the enter key event to prevent the page from automatically submitting. Along with this, i added code to move the focus to the next element in the tab index. When used in IE, the code works perfectly, but when i use it in firefox or chrome the focus jumps to the same box every time. I don't know what i'm doing wrong am i'm hoping someone can help me figure this out.
You can test the page at http://implicitarts.com/fandfwork/Lo...l/default.aspx
To start, go to the box for duty amount or freight charges and press enter
function handleKeyPress2(e,control)
{
var evt = e ? e : window.event;
var bt = control.id;
if (bt)
{
if (evt.keyCode == 13)
{
//bt.click();
jumptoNext(control, e);
stopEvent(e);
return false;
}
}
}
function jumptoNext(field, event)
{
for (i = 0; i < field.form.elements.length; i++)
if (field.form.elements[i].tabIndex == field.tabIndex + 1)
{
field.form.elements[i].focus();
if (field.form.elements[i].type == "text") field.form.elements[i].select();
break;
}
}
function stopEvent(e)
{
if (e.stopPropagation) e.stopPropagation();
else e.cancelBubble = true;
if (e.preventDefault) e.preventDefault();
else e.returnValue = false;
}
You don't need a code to use the TAB for circling through the forms elements (and the other focusable elements). That is the native behavior of all the browsers, by construction, anyway.
You have at least a JavaScript error here:
Code:
function processInlandOverride()
{
var OCValue = document.getElementById("txtOverrideInland").value;
if (isNaN(OCValue))
{
document.getElementById("lblInlandAmount").innerHTML = "";
document.getElementById("txtOverrideInland").value = "";
}
else
{
document.getElementById("lblInlandAmount").innerHTML = OCValue.toFixed(2);
}
}
toFixed() is a method of the primitive Number, not of the String. Make it:
I appreciate the reply, but if you found that error you saw that i coverted all values to a double number format, test to see if its a number, do processing, then call the toFixed() method. This function was just overlooked and i thank you for pointing out. I know that tab function is native to the browser, but if you refer to my original post, i stated that i capture the enter press event and move to the next field due to that event, which doesn't work correctly in all browsers.
There is something wrong with your function figureDisbursment(), which is called onblur from some of your elements. The focus jumps badly only from those fields which call that function onblur. If I remove (dynamically, using my FireBug) that functions from the onblur events, the focus jumps OK.
If some time, I will have a closer look.
I still think you have not managed the values in a proper way. You have a very intricate system to transform strings into numbers, using parseFloat() and isNaN(), while you could have simply used Number(). Number() returns 0 if the value is an empty string, while parseFloat() returns NaN, which gives you a supplementary trouble.
thank you for identifying a potential source. The cause for the call to the parsefloat() is because the for is used to generate bills to send to clients for billing; therefore the output had to be a decimal format. if there is a better way, please point me to the necessary resources.
call me crazy, but why would that function cause an issue in chrome and firefox, but not in internet exploer?
Bookmarks