PDA

View Full Version : onkeydown handling breaks in Firefox 1.0



georgeav
Jul 19th, 2006, 03:25 PM
Hi, I have the following code which works ok on Firefox 1.5 and IE6; but it doesn't on Firefox 1.0.7



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD lang="en">

<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" lang="en">

<script type="text/javascript">
function formatAmount(e)
{
var whichCode = (window.Event) ? e.which : e.keyCode;

document.all.bulls.value = '0.0'+whichCode;
return false;
}

</script>

</HEAD>
<INPUT style="text-align: right;" type="text" name="bulls" onkeydown="javascript:return(formatAmount(event));" size="13" maxlength="13" value="0.00">
</body>
</html>



As you can see I have an input which onkeydown runs a formating function (this is only a piece of the whole function). The ideea is that the function should read the key I pressed and change the value of the input to '0.0'+keyCode; but after formating, the event is not stopped and the key I press is added to the textbox.

Example: I press 1, the input should be 0.049 (and it is on IE6 and Firefox 1.5); but on Firefox 1.0.7 it's 0.0491.

Do you know how can I stop the event on Firefox 1.0.7 ?

Thanks,
George

vwphillips
Jul 19th, 2006, 04:45 PM
document.all is IE only

use gEBId IE5 on


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
</head>

<body>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD lang="en">

<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" lang="en">

<script type="text/javascript">
function formatAmount(e)
{
var whichCode = (window.Event) ? e.which : e.keyCode;

document.getElementById('bulls').value = '0.0'+whichCode;
return false;
}

</script>

</HEAD>
<INPUT style="text-align: right;" type="text" id="bulls" onkeydown="javascript:return(formatAmount(event));" size="13" maxlength="13" value="0.00">
</body>
</html>
</body>

</html>

georgeav
Jul 21st, 2006, 05:33 PM
Yes, I know.. but it works on Firefox too, this was piece of code written fast just to give you a full html, not JS functions and other pieces. The problem is that I can't stop the event.

George