Firefox/Mozilla and window.event.keyCode

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Perttu Pulkkinen

    Firefox/Mozilla and window.event.keyCode

    I have different functions that receive window.event as parameter. Functions
    are used like this:

    <input type="text" id="x"
    onkeypress="ret urn onKeyCurrencyCh eck(ev, 'x')"
    onblur ="onBlurCurrenc yCheck(event, 'x')"">

    Works very well with IE, but window.event and maybe window.event.ke ycode too
    seems to be missing form firefox. Is there a workaround for this?

    Perttu Pulkkinen



    function toCurrency(val)
    {
    if(val <0)
    { euros = Math.ceil(val); cents = Math.abs(Math.c eil(val*100) -
    euros*100); }
    else
    { euros = Math.floor(val) ; cents = Math.floor(val* 100) - euros*100; }
    if(cents <10) cents = "0" + cents;
    return euros +"." + cents;
    }
    /*************** *************** *************** *************/
    function onKeyCurrencyCh eck(ev, eleid)
    {
    ret = false;
    ele = getElement(elei d);
    if((48 <= ev.keyCode) && (ev.keyCode <= 57)) { ret = true;}
    else if(ev.keyCode == 8 || ev.keyCode == 46 ) {ret = true;}
    else if(ev.keyCode == 44) { ev.keyCode = 46; ret =
    true;}
    else if(ev.keyCode == 13) //enter
    {
    parsedvalue = parseFloat(ele. value);
    if(isNaN(parsed value) == false)
    { ele.value = toCurrency(pars edvalue); }
    else
    { ele.value ="0.00";}
    }
    return ret;
    }
    /*************** *************** *************** *************/
    function onBlurCurrencyC heck(ev, eleid)
    {
    ele = getElement(elei d);
    parsedvalue = parseFloat(ele. value);
    if(isNaN(parsed value) == false)
    { ele.value = toCurrency(pars edvalue); }
    else
    { ele.value ="0.00"; }
    }


    --
    Perttu Pulkkinen


  • Daniel Kirsch

    #2
    Re: Firefox/Mozilla and window.event.ke yCode

    Perttu Pulkkinen wrote:[color=blue]
    > I have different functions that receive window.event as parameter. Functions
    > are used like this:
    >
    > <input type="text" id="x"
    > onkeypress="ret urn onKeyCurrencyCh eck(ev, 'x')"
    > onblur ="onBlurCurrenc yCheck(event, 'x')"">
    >
    > Works very well with IE, but window.event and maybe window.event.ke ycode too
    > seems to be missing form firefox. Is there a workaround for this?[/color]

    Firefox doesn't use the global window.event but the passes an event
    object to the handler. However if you use just "event" it will work as
    this will be the event object within your handler.

    onkeypress="ret urn onKeyCurrencyCh eck(event, 'x')"

    keyCode is also know by firefox, but if you use keypress you may check
    for charCode.
    IIRC it also supports the old which property (event.which).

    Daniel

    Comment

    Working...