473,513 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

odd behavoir of alert in FF

can anyone explain why I get an endless loop of alerts (alert - hit enter -
alert - hit enter etc) from the following script/page?
It works ok in IE, and works ok in FF if I use the mouse to click the "ok",
but not if I use the enter key....

<html>
<head>
<title>Test</title>

<script type="text/javascript">
function updateForm(dom)
{
var qty = document.getElementById(dom).value;

if (qty != "")
if (qty == 0 || qty 5)
{
alert ("The number may not be 0 and not bigger than 5!");
document.getElementById(dom).select();
document.getElementById(dom).focus();
}
}
</script>
</head>

<body>
<form action="#">
Enter a number:
<!-- I changed value="0" to value="" -->
<td<input type = "text" name = "qty1" id = "qty1" value="" size="15"
onkeyup = "updateForm('qty1');" /</td>

</form>
</body>
</html>

regards

Michael
Nov 8 '06 #1
4 1581
Michael said the following on 11/7/2006 7:30 PM:
can anyone explain why I get an endless loop of alerts (alert - hit enter -
alert - hit enter etc) from the following script/page?
It works ok in IE, and works ok in FF if I use the mouse to click the "ok",
but not if I use the enter key....
Because the Enter key triggers the onkeyup for the input (which is
incorrect behavior to me).

Why are you passing a string that is the ID of the input and then
looking up that input with gEBI rather than just passing a reference to
the field and it's value?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 8 '06 #2

"Randy Webb" <Hi************@aol.comwrote in message
news:B8********************@telcove.net...
Michael said the following on 11/7/2006 7:30 PM:
>can anyone explain why I get an endless loop of alerts (alert - hit
enter - alert - hit enter etc) from the following script/page?
It works ok in IE, and works ok in FF if I use the mouse to click the
"ok", but not if I use the enter key....

Because the Enter key triggers the onkeyup for the input (which is
incorrect behavior to me).

Why are you passing a string that is the ID of the input and then looking
up that input with gEBI rather than just passing a reference to the field
and it's value?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/
Thanks for the reply Randy.

This was actually written by a fellow student, rather than me. I couldn't
figure out why it was behaving as it was and our tutor wasn't helping much
so I thought I'd ask here. I think this is probably a much cut own version
of a larger script, hence it seems a bit round about in its method.

So how does the keyup on the alert object cause the firing of the event
registered to the <inputobject? Why are they not separate?

Thanks for your help

Regards

Michael
Nov 8 '06 #3
it seems that when alert object receive onkeydown, it closed, and so
onkeyup is send to the input object.

"Michael дµÀ£º
So how does the keyup on the alert object cause the firing of the event
registered to the <inputobject? Why are they not separate?
Nov 8 '06 #4
Lee
Michael said:
>
can anyone explain why I get an endless loop of alerts (alert - hit enter -
alert - hit enter etc) from the following script/page?
It works ok in IE, and works ok in FF if I use the mouse to click the "ok",
but not if I use the enter key....

<html>
<head>
<title>Test</title>

<script type="text/javascript">
function updateForm(dom)
{
var qty = document.getElementById(dom).value;

if (qty != "")
if (qty == 0 || qty 5)
{
alert ("The number may not be 0 and not bigger than 5!");
document.getElementById(dom).select();
document.getElementById(dom).focus();
}
}
</script>
</head>

<body>
<form action="#">
Enter a number:
<!-- I changed value="0" to value="" -->
<td<input type = "text" name = "qty1" id = "qty1" value="" size="15"
onkeyup = "updateForm('qty1');" /</td>

</form>
</body>
</html>

Performing an action on a key-up event is risky in any GUI
language because you can never be sure that the corresponding
key-down occurred in the same focus. That seems to be the
problem here. The keydown event is seen by the alert window
and the keyup is seen by the input field.

Instead of "onkeyup", use "onkeypress" or "onchange".
--

Nov 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1420
by: Eyvind W Axelsen | last post by:
Hi. I am creating an application (primarily in C#), with MDI child windows. What I would like to do, is to override the default behavoir that makes a newly createad child form maximized if the...
24
4713
by: LineVoltageHalogen | last post by:
Greetings All, I was hoping that someone out there has run into this issue before and can shed some light on it for me. I have a stored procedure that essentially does a mini ETL from a source...
15
3197
by: optimistx | last post by:
How to write a function f(x) or f('x') so that it produces the same output as a call to alert-function: var x='abc'; alert('x='+x); In testing one needs to write similar alert() calls...
2
16847
by: schieco | last post by:
The following code always prints the debug lines inside the conditional if statement before and after the alert statement when the session has timed out, but the alert and redirect only appear/work...
4
3987
by: hugo2 | last post by:
Most of these characters are not on the standard keyboard. Here's a successful contrivance, with comments & cautions, a little page that works in IE6. <HTML><HEAD><SCRIPT TYPE="text/javascript">...
0
1671
by: Stephanie | last post by:
I have a problem with an Alert that is supposed to invoke a Job. Here are some details: Windows Server 2000 SQL Server Standard Ed. ver. 8.00.818 (Sp3) Alert: SQL Server performance condition...
3
9619
by: umdsasha | last post by:
So, basically, I need to detect whether an alert window was thrown. I can't find where it's thrown from but I need to disable a button only if there were no alert windows thrown. Any ideas? ...
22
2023
by: Daniel Rucareanu | last post by:
I have the following script: function Test(){} Test.F = function(){} Test.F.FF = function(){} Test.F.FF.FFF = function(){} Test.F.FF.FFF.FFFF = function(){} //var alias = function(){}; var...
24
8179
by: Jeremy J Starcher | last post by:
While reading c.l.j, I've noticed that some people prefer and indeed even recommend the use of "window.alert()" over "alert()". I can't find any technical reason to make this distinction, and...
0
7260
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
7160
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...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5086
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3233
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.