...it works in IE.
kc
...it works in IE.
kc
Unfortunately it doesn't work with Firefox "out of the box". But I did some debugging and with 3 changes you should be able to get it to work in most browsers.
1.<script for="window" event="onload" language="javascript">
...</script>
In Firefox, this script is executed before the controls on the page exist, which causes problems. Besides, according to the standard,script
does not have attributes called "for" or "event". The simplest fix is to take out this script block, then find your<body>
tag and change it to:
<body onload="RecomputeHand();">
2.frmStrat
You'll need to replacefrmStrat
withdocument.frmStrat
in all your Javascript (i.e. everywhere except in theform
tag itself).
3.txtDecks_onkeypress
This looks like one of those areas where broswer behaviour isn't fully standardised. I found an explanation and a workaround here. In theinput
tag for txtDecks, add "event" as a parameter to txtDecks_onkeypress like this:
onkeypress="return txtDecks_onkeypress(event)"
Then replace yourtxtDecks_onkeypress
function with:
function txtDecks_onkeypress(e) {
var key = window.event ? e.keyCode : e.which;
if (! (key >= 48 && key <= 57))
e.returnValue = false;
}
Hope this helps.
> Unfortunately it doesn't work with Firefox "out> onload="RecomputeHand();"> 2. frmStrat
> of the box". But I did some debugging and with 3
> changes you should be able to get it to work in most
> browsers.
> 1. > event="onload"
> language="javascript"> ...
> In Firefox, this script is executed
> before the controls on the page exist, which causes
> problems. Besides, according to the standard, script
> does not have attributes called "for" or
> "event". The simplest fix is to take out
> this script block, then find your tag
> and change it to:
>
> Unfortunately it doesn't work with Firefox "out
> of the box". But I did some debugging and with 3
> changes you should be able to get it to work in most
> browsers.
> 1. In Firefox, this script is executed
> before the controls on the page exist, which causes
> problems. Besides, according to the standard, script
> does not have attributes called "for" or
> "event". The simplest fix is to take out
> this script block, then find your tag
> and change it to:
>
> onload="RecomputeHand();"
I changed from event="onload" to event="onload()" (void parameter list.)
This still works in IE. I think (could be wrong) that defining window onload
like I did is supposed to override window onload in the body element. I found that
some make use of this to open popup windows with window.open("http...,height,
width,scrollbars,resizable,etc."). I mostly don't like those, but I suppose
they could be used in good taste. Maybe that's why this
doesn't work in Firefox. If the change I made doesn't work I'll try
defining onload in the body element.
>2. frmStrat
> You'll need to replace frmStrat with
> document.frmStrat in all your Javascript (i.e.
> everywhere except in the form tag itself).
I qualified frmStrat with document.frmStrat as you suggested.
> 3. txtDecks_onkeypress This looks like one of those
> areas where broswer behaviour isn't fully
> standardised. I found an explanation and a workaround
> here . In the input tag for txtDecks, add
> "event" as a parameter to
> txtDecks_onkeypress like this:
> onkeypress="return
> txtDecks_onkeypress(event)" Then replace your
> txtDecks_onkeypress function with:
> function txtDecks_onkeypress(e) {
> var key = window.event ?
> e.keyCode : e.which;
> if (! (key >= 48 && key <= 57)
> e.returnValue = false;
I basically did as you suggested:
function txtDecks_onkeypress(event) {
if (! (event.keyCode >= 48 && event.keyCode <= 57))
event.returnValue = false;
}
It works in IE. I'm not sure if I'll need to qualify event as window.event
for other browsers, but it seems to maybe make sense that I shouldn't since I'm
not passing window.event to the function.
> } Hope this helps.
Once again, it does .
kc
> I qualified frmStrat with document.frmStrat as you
> suggested.
That one change made about 90% of your code work. I can actually get strategies now.
> I changed from event="onload" to
> event="onload()" (void parameter list.)
> This still works in IE. I think (could be wrong) that
> defining window onload
> like I did is supposed to override window onload in
> the body element. I found that
> some make use of this to open popup windows with
> window.open("http...,height,
> width,scrollbars,resizable,etc."). I mostly don't
> like those, but I suppose
> they could be used in good taste. Maybe that's why
> this
> doesn't work in Firefox. If the change I made doesn't
> work I'll try
> defining onload in the body element.
Sorry, that didn't help. When I load the page I get an error in the JavaScript Console that says:
document.frmStrat has no properties
I think this is because when Firefox runs this code it hasn't loaded the rest of the page yet, whereas IE loads the whole page before running it. (Again, probably something that isn't covered in the spec.) You could try moving this script to the bottom of your page but I've tried using thebody
tag's onload attribute and it seems to work.
> I basically did as you suggested:
> function txtDecks_onkeypress(event) {
> if (! (event.keyCode >= 48 && event.keyCode
> event.returnValue = false;
> }
> It works in IE. I'm not sure if I'll need to qualify
> event as window.event
> for other browsers, but it seems to maybe make sense
> that I shouldn't since I'm
> not passing window.event to the function.
The difficulty here is that Firefox and Netscape don't useevent.keyCode
, they useevent.which
whereas IE usesevent.keyCode
but notevent.which
. (Opera tries to please everybody and uses both.) I discovered this from the page I linked to last time (Tutorials - KeyPress validation).
That page also presents a solution which is to get the value of the key pressed with this expression:
var key = window.event ? e.keyCode : e.which;
This usese.keyCode
ifwindow.event
is defined ande.which
if it isn't. From the table on the page you can see that those browsers that setwindow.event
also sete.keyCode
, whereas those that don't sete.which
. This is what I'd call a "clever hack".
> Once again, it does .
No problem. We might be getting a bit off-topic here, even for the Computing for Counters forum. Feel free to email me if you wish.
The window.onload function is working now but in txtDecks_onkeypress,event.returnValue = false;
needs to be replaced withreturn false;
.
Bookmarks