473,805 Members | 2,008 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.getEle mentById(dom).v alue;

if (qty != "")
if (qty == 0 || qty 5)
{
alert ("The number may not be 0 and not bigger than 5!");
document.getEle mentById(dom).s elect();
document.getEle mentById(dom).f ocus();
}
}
</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('qt y1');" /</td>

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

regards

Michael
Nov 8 '06 #1
4 1597
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.javas cript 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******** ************@te lcove.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.javas cript 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.getEle mentById(dom).v alue;

if (qty != "")
if (qty == 0 || qty 5)
{
alert ("The number may not be 0 and not bigger than 5!");
document.getEle mentById(dom).s elect();
document.getEle mentById(dom).f ocus();
}
}
</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('qt y1');" /</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
1441
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 topmost childform that already exists is also maximized. Furthermore, if I maximize one form, I don't want all the other forms to be maximized, and the same thing goes for 'restoring' forms to their original size. Any ideas?
24
4755
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 OLTP DB to a the target Operational Data Store. This is still in development so both DB's reside on the same machine for convenience. The stored proc runs successfully from within Query analyzer and this holds true on the following platforms: XP...
15
3224
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 often. By having a function f(), which would add the variable name in front of the variable value one would save a lot of typing during one's lifetime.
2
16866
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 in certain situations. <% // Check for expired session log.debug("session ID = " + session.getAttribute("session_loginID")); if (session.getAttribute("session_loginID") == null)
4
4023
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"> function alt() { document.all.s1.innerHTML="Current Temp: 68°F"; var txt=document.all.s1.innerText; alert(txt); }
0
1681
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 alert; Counter: Percent Log Used; If the counter rises above 90% the response is to execute Job. Job: Transaction Log backup; set up through the Database Maintenance Plans. This job runs a backup hourly during the day, on a couple of the...
3
9717
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? Thanks Alex
22
2070
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 alias = Test.F.FF.FFF.FFFF;
24
8238
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 seems to have a (tiny) amount overhead since window itself points to the global object, hence, a circular reference. (From everything I am reading, window is just a REFERENCE back to the global object, as opposed to a separate object.)
0
9718
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10613
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10368
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7649
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5544
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3008
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.