473,384 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Cancel Event in Firefox

I have a function which needs to cancel the input into a text field on
a form. I cancel the event in IE fine and the text does not get
entered. But for firefox (1.0) I cancel the event and the text still
gets entered.

I've stripped the function down just to try to get it to work in
Firefox. The alert does happen on the keydown event so it should be
cancellable.

function formatInput(e){
if (e.cancelable){
e.preventDefault()
alert("Event is cancelable")
}
}

How can I cancel the input??

Nov 4 '05 #1
11 18317
Rob
ry******@yahoo.com wrote:
I have a function which needs to cancel the input into a text field on
a form. I cancel the event in IE fine and the text does not get
entered. But for firefox (1.0) I cancel the event and the text still
gets entered.

I've stripped the function down just to try to get it to work in
Firefox. The alert does happen on the keydown event so it should be
cancellable.

function formatInput(e){
if (e.cancelable){
e.preventDefault()
alert("Event is cancelable")
}
}

How can I cancel the input??


Why not just disable the text field, blur it, and erase whatever was
entered?

Nov 4 '05 #2
Cause I do not want to disable it. That was a stripped function to try
to get it to work. I only want to cancel the event on certain keyCodes
not ALL keyCodes. You can't erase a delete, or an End or a Home, etc.
Anyone know how to cancel the event so it does not continue with the
keyCode pressed?
Rob wrote:
ry******@yahoo.com wrote:
I have a function which needs to cancel the input into a text field on
a form. I cancel the event in IE fine and the text does not get
entered. But for firefox (1.0) I cancel the event and the text still
gets entered.

I've stripped the function down just to try to get it to work in
Firefox. The alert does happen on the keydown event so it should be
cancellable.

function formatInput(e){
if (e.cancelable){
e.preventDefault()
alert("Event is cancelable")
}
}

How can I cancel the input??


Why not just disable the text field, blur it, and erase whatever was
entered?


Nov 4 '05 #3
VK

ry******@yahoo.com wrote:
Cause I do not want to disable it. That was a stripped function to try
to get it to work. I only want to cancel the event on certain keyCodes
not ALL keyCodes. You can't erase a delete, or an End or a Home, etc.
Anyone know how to cancel the event so it does not continue with the
keyCode pressed?


The main rule is: you have to return false from the event handler to
cancel an event. The code below works for FF 1.0.7

Please not that:
1) In intrisic event handlers (textbox txt1) you have to return false
*from the handler itself* - not from the function called by the
handler. I guess that was your original problem.

2) There is a nasty bug in current versions of FireFox. Typing any text
in a textbox leads to the security exception (you can check the
JavaScript console). It doesn't break the script, but it causes a small
delay in the execution. If you additionally pass each input event
through a custom check, this delay may get noticable. The only
workaround I'm aware of in setting autocomplete to false; but it's not
always suitable.

<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
/* Script for FireFox and Gesko-based only */

function f(e) {
if (String.fromCharCode(e.which).
toUpperCase() == 'A') {
return false;
}
else {
return true;
}
}

function init() {
document.forms[0].elements['txt2'].onkeypress = f;
}

window.onload = init;
</script>
</head>

<body>

<form method="post" action="">
<input type="text" autocomplete="false" name="txt1" onkeypress="return
f(event)">
<input type="text" autocomplete="false" name="txt2">
</form>

</body>
</html>

Nov 5 '05 #4
VK,
Thanks for the reply. I am aware that I can stop it by returning
false on the actual event attribute. But my issue is that the function
is attached to the event via javascript and so unable to return a value
as JavaScript states.

So what you saying is the FireFox documentation on e.cancelable
e.preventDefault() are completely BS? The preventDefault should stop
the normal functionality from occuring but does not??? Although I
believe you I just don't understand why this is so.

Is there anyway around this. The function MUST be attached via
JavaScript so returning false is out of the question. Thanks for any
help you could provide.

Nov 8 '05 #5
VK

ry******@yahoo.com wrote:
So what you saying is the FireFox documentation on e.cancelable
e.preventDefault() are completely BS? The preventDefault should stop
the normal functionality from occuring but does not??? Although I
believe you I just don't understand why this is so.


It is not BS (at least not all of it :-)
Simply window.status is a *legacy* interface from Netscape. And usually
when you are dealing with legacy you have to forget any common as well
as any particular sense and just do what is working.

Status change requires return true from the same context where the
change has been made:
window.status = myText;
return true;

These statements have to be in this order and within the same context.
There is no any reason in it, like there is no reason in the hill
behind my window. It just here.
You may do not like Microsoft, but one thing you have to give them a
credit for (?): if a standard and the common sense are in
contradiction, they choose the common sense.

Intrinsic event handlers are really anonymous functions. So fragment
like:
<a href="foo.html" onmouseover="window.status='Hello!';return true;"...

in the reality is:
<a href="foo.html" onmouseover="
function anonymous() {
window.status='Hello!';
return true;
}"...
and it's fine

But
<a href="foo.html" onmouseover="myFunction('Hello!');"...
in the reality is:
<a href="foo.html" onmouseover="
function anonymous() {
myFunction('Hello!');
}"...
And now you can see clearly that it is not matter what will you return
from myFunction(): function anonymous() will still return undefined to
the handler.

Now you can guess that the programmed handler:
myHref.onmouseover = myFunction;
in the reality is a reproduction of the same situation
but even in worse case because you are left w/o possibility to
pass arguments:
myHref.onmouseover= function() {myFunction();}

And the only way I can think of to overpass this legacy crazyness is to
use anonymous function right on the handler:
myHref.onmouseover = function() {
window.status = 'Hello!';
return true;
}

The last finally works for FF (if "Change status bar text" option is
enabled).

Nov 8 '05 #6
VK wrote:
Simply window.status is a *legacy* interface from Netscape.


It is not. It is a proprietary, yet widely implemented, property
of a (proprietary, yet widely implemented) host object.
PointedEars
Nov 8 '05 #7
VK
>> VK wrote:
Simply window.status is a *legacy* interface from Netscape.
Thomas 'PointedEars' Lahn wrote:
It is not. It is a proprietary, yet widely implemented, property
of a (proprietary, yet widely implemented) host object.


I'm wondering what *proprietary* means for you? Something that it was
not originally invented/proposed by W3C? Then the every single piece of
HTML/DOM/JavaScript is proprietary and used to deliver information over
proprietary media (WWW) to proprietary interface (browser). No one of
these things is W3C discover or achievement. W3C is just a more-or-less
reliable standartisation unit, not a development lab.

Data Binding is proprietary, XPConnect is proprietary. Whatever was
made before any smell of W3C is *legacy*.

Nov 8 '05 #8
VK wrote:
VK wrote:
> Simply window.status is a *legacy* interface from Netscape.
Thomas 'PointedEars' Lahn wrote:
You really want to learn how to quote properly.
<http://www.jibbering.com/faq/faq_notes/clj_posts.html>
It is not. It is a proprietary, yet widely implemented, property
of a (proprietary, yet widely implemented) host object.


I'm wondering what *proprietary* means for you?


Essentially it means to me (and others) "not specified in or by a
public standard, implemented only by one or more specific vendors".
Something that it was not originally invented/proposed by W3C?
No. Something not specified by W3C, iff there is a W3C standard
for it. You may replace "W3C" with the name of any acknowledged
standardization body.
Data Binding is proprietary, XPConnect is proprietary.
Correct.
Whatever was made before any smell of W3C is *legacy*.


No. And "Legacy" implies "obsolete".
PointedEars
Nov 9 '05 #9
VK,
I love your view on the common sense verse standards! Do you know of
a way to cancel the event with a function that is attached using the
addEventListener in FireFox? Or is that asking too much? I've been
trying but no cigar. Thanks again for all your help on this.

Ryan

Nov 9 '05 #10
VK wrote:
You may do not like Microsoft, but one thing you have to give them a
credit for (?): if a standard and the common sense are in
contradiction, they choose the common sense.


Which is why it (probably) took IE_7_ to achieve basic Web standards.
You made my day.
PointedEars
Nov 9 '05 #11
VK

ry******@yahoo.com wrote:
VK,
I love your view on the common sense verse standards! Do you know of
a way to cancel the event with a function that is attached using the
addEventListener in FireFox? Or is that asking too much? I've been
trying but no cigar. Thanks again for all your help on this.


As much as I can tell (I'm all in debugging of my new prog right now so
no testing) addEventListener will not work by definition because

ahref.addEventListener('mouseover',myfunc,false)

is

ahref.onmouseover = function anonymous() {myfunc();}

and see my previous answer.

This deadlock happened during the FF growthup when they did not dare to
make a fart w/o W3C written permission. This year the child finally
reached the age to "understand how stupid really parents are": so you
may file a complain to bugzilla.mozilla.org and have a hope that they
will fix it as Microsoft did.

Nov 9 '05 #12

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

Similar topics

1
by: WindAndWaves | last post by:
Goodmorning Gurus Here is another of my questions..... When adding code to a control then access sometimes puts in a couple of 'parameters'. Can anyone tell me what the use of them is. I have...
1
by: AP | last post by:
Hi, I'm trying to use c# to pop up a dialog box when a user attempts to close word to prompt them if they want to exit or cancel (obviously other stuff needs to happen based on their selection...
0
by: PeacError | last post by:
Using Microsoft Visual Studio .NET 2003, Visual C# .NET 1.1: I apologize if this question has been addressed elsewhere, but I could not find a reference to it in the search engine for this...
3
by: Charles Law | last post by:
Under what circumstances would e.Cancel be set to True on entry to the Closing event of an MDI child form? I have found that this is why my application won't close properly. I can explicitly set...
6
by: Peter M. | last post by:
Hi all, If an event has multiple subscribers, is it possible to cancel the invocation of event handlers from an event handler? Or to be more specific: I'm subscribing to the ColumnChanging...
3
by: adbo_atoz | last post by:
Hello All I am trying to duplicate this code which works in IE to work in Firefox <SCRIPT LANGUAGE="javascript"> function submitOnEnterKey() { if(event.keyCode == 13) { event.returnValue...
21
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on...
4
by: Academic | last post by:
Does it make sense to put this If e.Cancel Then Exit Sub at the beginning of form closing events so if the user cancels the app's exiting in one Closing routine he will not be asked again by...
3
by: Smithers | last post by:
In consideration of the brief sample code at the following link... http://msdn2.microsoft.com/en-us/library/system.componentmodel.canceleventargs.cancel.aspx .... when we set e.Cancel = true,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.