www.webdeveloper.com
Results 1 to 5 of 5

Thread: Javascript not working across browsers

  1. #1
    Join Date
    Mar 2011
    Posts
    3

    Javascript not working across browsers

    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;
    }

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    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:
    Code:
    document.getElementById("lblInlandAmount").innerHTML = Number(OCValue).toFixed(2);

  3. #3
    Join Date
    Mar 2011
    Posts
    3
    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.

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    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.

  5. #5
    Join Date
    Mar 2011
    Posts
    3
    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?
    Last edited by delcarta; 03-24-2011 at 03:20 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles