Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > odd behavoir of alert in FF

Reply
Thread Tools

odd behavoir of alert in FF

 
 
Michael
Guest
Posts: n/a
 
      11-08-2006
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


 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      11-08-2006
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/
 
Reply With Quote
 
 
 
 
Michael
Guest
Posts: n/a
 
      11-08-2006

"Randy Webb" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 <input> object? Why are they not separate?

Thanks for your help

Regards

Michael


 
Reply With Quote
 
buhailiang
Guest
Posts: n/a
 
      11-08-2006
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 <input> object? Why are they not separate?
>


 
Reply With Quote
 
Lee
Guest
Posts: n/a
 
      11-08-2006
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".


--

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
modify "Close Group" behavoir in X64? MsFriendly Windows 64bit 5 02-28-2008 04:26 PM
modify "Close Group" behavoir in X64? MsFriendly Windows 64bit 0 02-26-2008 08:19 AM
sscanf behavoir Joachim Schmitz C Programming 7 04-20-2007 06:41 AM
Processes with strange behavoir Markus Franz Python 2 04-04-2004 08:29 PM
Strange .avi file behavoir Croos Bustamunky Computer Support 2 02-03-2004 06:54 AM



Advertisments