472,782 Members | 1,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,782 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 20696
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.