473,689 Members | 2,890 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Even canceling in Firefox

Hi!

I want to cancel up and down arrows in list (select) element.
Here is the code:

<script>

function Arrows (event)
{
code = event.keyCode;
if (code == 38)
alert('Up');

if (code == 40)
alert('Down');
if (event.stopProp agation)
event.stopPropa gation();
else
event.cancelBub ble = true;

if (event.preventD efault)
event.preventDe fault();
else
event.returnVal ue = false;
return false;
};
</script>

<form id="theform">
<select id="answ" name="answ" style="width:30 0px"
multiple size="5" onkeydown="retu rn Arrows(event);" >
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three </option>
<option value="4">four</option>
<option value="5">five</option>
</select>
</form>
It works in IE but doesn't in Firefox. Any ideas how to fix it?

Marcin
--
Marcin Nowak
www.wyprawa.net .ch.o_mi.k_@.c. ho_m.ik.n_et_
Ochrona adresu: usun kropki z wyjatkiem ostatniej, podkreslenia
oprócz pierwszego. Address protection: remove dots except for
the last one, underscores excluding the first one.
Feb 20 '06 #1
8 1780
VK

Marcin Nowak wrote:
<select id="answ" name="answ" style="width:30 0px"
multiple size="5" onkeydown="retu rn Arrows(event);" >


SELECT supports by specs onfocus, onchange, onblur. Whatever and
*however* it supports atop of it is up to the fantasy of a particular
browser producer.

In your case I would make a CSS widget instead.

Also you may to repopulate the list based on the selected items.
Infortunately the most evident way by setting disabled true/false for
option or optgroup doesn't work in IE (despite documented).

Feb 20 '06 #2
VK wrote:
Marcin Nowak wrote:
<select id="answ" name="answ" style="width:30 0px"
multiple size="5" onkeydown="retu rn Arrows(event);" >
SELECT supports by specs onfocus, onchange, onblur.


That is not quite correct. It supports more event handler attributes than
those:

,-[from HTML 4.01 Strict; compacted whitespace]
|
| <!ELEMENT SELECT - - (OPTGROUP|OPTIO N)+ -- option selector -->
| <!ATTLIST SELECT
| %attrs; -- %coreattrs, %i18n, %events --
^^^^^^^ ^^^^^^^
| name CDATA #IMPLIED -- field name --
| size NUMBER #IMPLIED -- rows visible --
| multiple (multiple) #IMPLIED -- default is single selection --
| disabled (disabled) #IMPLIED -- unavailable in this context --
| tabindex NUMBER #IMPLIED -- position in tabbing order --
| onfocus %Script; #IMPLIED -- the element got the focus --
| onblur %Script; #IMPLIED -- the element lost the focus --
| onchange %Script; #IMPLIED -- the element value was changed --
| >
| [...]
| <!ENTITY % attrs "%coreattrs ; %i18n; %events;">
| [...]
| <!ENTITY % events
| "onclick %Script; #IMPLIED -- a pointer button was clicked --
| ondblclick %Script; #IMPLIED -- a pointer button was double clicked --
| onmousedown %Script; #IMPLIED -- a pointer button was pressed down --
| onmouseup %Script; #IMPLIED -- a pointer button was released --
| onmouseover %Script; #IMPLIED -- a pointer was moved onto --
| onmousemove %Script; #IMPLIED -- a pointer was moved within --
| onmouseout %Script; #IMPLIED -- a pointer was moved away --
| onkeypress %Script; #IMPLIED -- a key was pressed and released --
| onkeydown %Script; #IMPLIED -- a key was pressed down --
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^
| onkeyup %Script; #IMPLIED -- a key was released --"
| >
Whatever and *however* it supports atop of it is up to the fantasy of
a particular browser producer.
True, if you read that statement in context. False otherwise.
In your case I would make a CSS widget instead.


Whereas the reason that it does not work in Firefox has nothing to do with
the markup at all (although it is not Valid). Firefox does support the
specified `onkeydown' event handler attribute for `select' elements used
here.
PointedEars
Feb 20 '06 #3
Marcin Nowak wrote:
I want to cancel up and down arrows in list (select) element.
Here is the code:
[...]
It works in IE but doesn't in Firefox.
"Does not work" is a useless error description. [psf 4.11]

<URL:http://jibbering.com/faq/#FAQ4_43>
Any ideas how to fix it?


I do question your crippling keyboard navigation, and the code is not
Valid markup[1] (however, the `select' element does have an `onkeydown'
attribute, ignore VK).

It works though, i.e. the alert box displays the proper value ("Up"/"Down")
and the selection does not change, for me unchanged (included in an
otherwise Valid HTML 4.01 document) in

Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.1) Gecko/20060209
Debian/1.5.dfsg+1.5.0. 1-2 Firefox/1.5.0.1.

The only thing I get is

| Warning: assignment to undeclared variable code
| Source file: http://localhost/scripts/test/dom/ev...lect-onkeydown
| Line: 13
| code = event.keyCode;
| -------^

(You should use the `var' keyword to declare this a local variable.)

So the error must be elsewhere.
PointedEars
___________
[1] <URL:http://validator.w3.or g/>
Feb 20 '06 #4


Marcin Nowak wrote:

function Arrows (event)
{
code = event.keyCode;
if (code == 38)
alert('Up');

if (code == 40)
alert('Down');
if (event.stopProp agation)
event.stopPropa gation();
else
event.cancelBub ble = true;

if (event.preventD efault)
event.preventDe fault(); <select id="answ" name="answ" style="width:30 0px"
multiple size="5" onkeydown="retu rn Arrows(event);" >


Cross browser key event cancelling is difficult, if you are trying that
with Firefox 1.0.x then trying onkeydown does help, Firefox 1.0.x can
only cancel keys onkeypress.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 20 '06 #5
Martin Honnen wrote:
Cross browser key event cancelling is difficult, if you are trying that
with Firefox 1.0.x then trying onkeydown does help, Firefox 1.0.x can
only cancel keys onkeypress.


Huh? :)

Did you mean "... with Firefox 1.5.0.x ..., Firefox 1.0.x can only ..."?
PointedEars
Feb 20 '06 #6


Thomas 'PointedEars' Lahn wrote:
Martin Honnen wrote:

Cross browser key event cancelling is difficult, if you are trying that
with Firefox 1.0.x then trying onkeydown does help, Firefox 1.0.x can
only cancel keys onkeypress.


Huh? :)


Sorry, a 'not' got lost, it should have been
"if you are trying that with Firefox 1.0.x then trying onkeydown does
not help, Firefox 1.0.x can only cancel keys onkeypress."
--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 20 '06 #7
Thomas 'PointedEars' Lahn napisał(a):
Marcin Nowak wrote:
I want to cancel up and down arrows in list (select) element.
Here is the code:
[...]
It works in IE but doesn't in Firefox.


"Does not work" is a useless error description. [psf 4.11]


Event is not canceled - that is what doesn't work.
Focus is in input element, I press down arrow. My function
changes focus to 'option' element (first line of 'option' is
selected) and tries to cancel event. After function ends, the
down arrow keeps working - this event changes selection to the
second line of 'option' element.

Marcin
--
Marcin Nowak
www.wyprawa.net .ch.o_mi.k_@.c. ho_m.ik.n_et_
Ochrona adresu: usun kropki z wyjatkiem ostatniej, podkreslenia
oprócz pierwszego. Address protection: remove dots except for
the last one, underscores excluding the first one.
Feb 20 '06 #8
Marcin Nowak wrote:
Thomas 'PointedEars' Lahn napisał(a):
Marcin Nowak wrote:
I want to cancel up and down arrows in list (select) element.
Here is the code:
[...]
It works in IE but doesn't in Firefox.


"Does not work" is a useless error description. [psf 4.11]


Event is not canceled - that is what doesn't work.
Focus is in input element, I press down arrow. My function
changes focus to 'option' element (first line of 'option' is
selected) and tries to cancel event. After function ends, the
down arrow keeps working - this event changes selection to the
second line of 'option' element.


Well, as Martin's posting indicates, either you are using Firefox <= 1.0.x
(or probably any Mozilla/5.0 with rv < 1.7 for that matter[1]), or your
Firefox 1.5.0.x is buggy and this should be reported on Bugzilla (if
someone did not do that before). Because it does work in my Firefox
1.5.0.1/Linux (even though it is not Valid), as I wrote already.
PointedEars
___________
[1] tested working with
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20060205
Debian/1.7.12-1.1
Feb 20 '06 #9

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

Similar topics

0
1902
by: Allan Bredahl | last post by:
Hi All I am trying to construct an application that is able to cancel a machine shutdown, reboot or logoff. And after performing some stuff to perform the original shutdown order : Shutdown/reboot/logoff. I have tried this : AddHandler Microsoft.Win32.SystemEvents.SessionEnding, AddressOf
4
4060
by: welie | last post by:
I have a problem canceling a check box update when placing a check in it. Checkbox is not bound. Here is what happens. User clicks a check box. In the BeforeUpdate method of the control, if the check box is being checked, some validation is performed. If the validation fails, I set cancel to true, and the check box is not checked afterwards. This is fine.
11
6647
by: Tore Halset | last post by:
Hello. I am trying to port an old java application from MS SQL Server to PostgreSQL running on Mac OS X. I have access to the java source code and can make modifications. I have tried with PostgreSQL version 7.4.2 and 8.0.0beta2, but get the same error. I am using pgdev.305.jdbc3.jar for 8.0.0beta2. The PostgreSQL installation are standard, except for log_statement = 'all' to debug this problem. The problem is that the server returns...
0
1237
by: Bart McFarling | last post by:
postgres 7.4.2 on a RedHat Enterprise Server using libpq on SCO Open Server Seems that if a command takes too long I get ERROR:Canceling query due to user request. I have ulimit=unlimited postgresql.conf has statement_timeout = 0 Any ideas on what could be causing this?
0
1642
by: rcarmich | last post by:
I am having an issue canceling a beginReceive call on a timeout. For example, the following function: public int ReadBytes(Socket theSock, byte arr, int startByte, int length, int timeout) { IAsyncResult result = theSock.BeginReceive(arr, startByte, length, SocketFlags.None, null, null); if (result.AsyncWaitHandle.WaitOne(timeout, false) ==
1
2021
by: ishay44 | last post by:
I use Winsock2 (WS2_32.DLL) and i want to canceling the 'select()' blocking, in Windows Sockets 1.1 it was possible using the WSACancelBlockingCall(), but it removed for Winsock2 so how can cancel this blocking now?
2
1833
TonFrere
by: TonFrere | last post by:
Hello, I'm building a solution using Visual Studio Windows Forms and I'm coding in C#. I have a windows form with databinded textboxes, comboboxes and a datagrid. Everything works fine until a user enter a wrong value in a textbox binded to a numeric field on the form. There is no way to get back to the old value by pressing escape (canceling changes). Strangely, this works fine with the datagridview columns: if there is an error in a...
25
5171
bugboy
by: bugboy | last post by:
I'm trying to find a cross browser solution for editing text in a flickr photo caption manor where the text is displayed in a <div> or <a> tag but changes to a <textarea> via JS when clicked. There are two problems. 1. setting the focus on the new textarea 2. keeping the new text value when switching back to normal text. Firefox: focuses fine but does not keep the new text value Safari: focuses then instantly looses focus again, and...
0
8594
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
9076
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...
0
7621
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6454
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
5810
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
4321
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
4547
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2219
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1952
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.