472,364 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 software developers and data experts.

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.stopPropagation)
event.stopPropagation();
else
event.cancelBubble = true;

if (event.preventDefault)
event.preventDefault();
else
event.returnValue = false;
return false;
};
</script>

<form id="theform">
<select id="answ" name="answ" style="width:300px"
multiple size="5" onkeydown="return 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 1705
VK

Marcin Nowak wrote:
<select id="answ" name="answ" style="width:300px"
multiple size="5" onkeydown="return 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:300px"
multiple size="5" onkeydown="return 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|OPTION)+ -- 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.org/>
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.stopPropagation)
event.stopPropagation();
else
event.cancelBubble = true;

if (event.preventDefault)
event.preventDefault(); <select id="answ" name="answ" style="width:300px"
multiple size="5" onkeydown="return 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
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 :...
4
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...
11
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...
0
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...
0
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) {...
1
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...
2
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...
25
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. ...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.