473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 20735
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Peter Adolphs | last post by:
Hi newsgroup! The W3C HTML 4.01 recommendation states that "The onreset event occurs when a form is reset." Using Mozilla 1.4.1, how come that if I set onreset="return false;", the form is not...
6
by: Justin Beasley | last post by:
Here is an answer for those who are looking for a keystroke evaluation script that works in Internet Explorer (IE 5.5, 6.0, 7.0 for PC--IE 4.0, 5.2 for Mac), Mozilla Firefox (Windows, Linux, and...
6
by: rich_poppleton | last post by:
Help.... I've got a textarea where people type in a description. However for certain reasons we need to stop them typing !$*^ . I have a solution this which works fine in IE: function...
3
by: niconedz | last post by:
Hi The following code works fine in IE but not Firefox. It's a little script that zooms an image and resizes the window to fit. Can anybody tell me what's wrong? Thanks Nico == btw.....
7
by: prado | last post by:
Hi, I am trying to disable the F5 key in Mozilla. I have the next code in javascript that it is working in Internet Explorer but it is not working in Mozilla. how can I disable the F5 key in...
1
by: nebulus | last post by:
I'm working on a web app that under normal circumstances will be happy with the Session_OnEnd event, but when a user leaves a page by closing the browser by either Alt+F4 or just hitting the "X",...
1
by: acl123 | last post by:
Hi, I am trying to work out how to access the event object in firefox under two conditions - 1) Attaching event handlers in javascript, not html. 2) The event handler requires parameters in...
33
by: buss123 | last post by:
Hi all, combo box script code was working in IE perfectly with all modes but OnChange event was not working in FireFox(editable mode, if we select valuese that combo box values r...
1
by: sva0008 | last post by:
i have a auto suggest script that does not work in firefox , works great on IE. /******************************************************* AutoSuggest - a javascript automatic text input...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.