471,066 Members | 964 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

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="return onKeyCurrencyCheck(ev, 'x')"
onblur ="onBlurCurrencyCheck(event, 'x')"">

Works very well with IE, but window.event and maybe window.event.keycode 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.ceil(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 onKeyCurrencyCheck(ev, eleid)
{
ret = false;
ele = getElement(eleid);
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(parsedvalue) == false)
{ ele.value = toCurrency(parsedvalue); }
else
{ ele.value ="0.00";}
}
return ret;
}
/************************************************** ********/
function onBlurCurrencyCheck(ev, eleid)
{
ele = getElement(eleid);
parsedvalue = parseFloat(ele.value);
if(isNaN(parsedvalue) == false)
{ ele.value = toCurrency(parsedvalue); }
else
{ ele.value ="0.00"; }
}
--
Perttu Pulkkinen
Jul 23 '05 #1
1 20587
Perttu Pulkkinen wrote:
I have different functions that receive window.event as parameter. Functions
are used like this:

<input type="text" id="x"
onkeypress="return onKeyCurrencyCheck(ev, 'x')"
onblur ="onBlurCurrencyCheck(event, 'x')"">

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


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="return onKeyCurrencyCheck(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
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Peter Adolphs | last post: by
6 posts views Thread by Justin Beasley | last post: by
6 posts views Thread by rich_poppleton | last post: by
3 posts views Thread by niconedz | last post: by
7 posts views Thread by prado | last post: by
1 post views Thread by sva0008 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.