473,594 Members | 2,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.preventDefaul t()
alert("Event is cancelable")
}
}

How can I cancel the input??

Nov 4 '05 #1
11 18336
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.preventDefaul t()
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.preventDefaul t()
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.fromCha rCode(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="f alse" name="txt1" onkeypress="ret urn
f(event)">
<input type="text" autocomplete="f alse" 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.preventDefaul t() 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.preventDefaul t() 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="wi ndow.status='He llo!';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="my Function('Hello !');"...
in the reality is:
<a href="foo.html" onmouseover="
function anonymous() {
myFunction('Hel lo!');
}"...
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.onmouseo ver = 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.onmouseo ver= 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.onmouseo ver = 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.c om/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
addEventListene r 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

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

Similar topics

1
15963
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 never used them, but I would be keen to do so. Here is an example for a control (on a form) called CNW, when I add some code for the BeforeUpdate event, access puts in the following lines. Private Sub CNW_BeforeUpdate(******Cancel As...
1
8330
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 but that's the gist of it.) I have everything set up, and it seems to work except that setting Cancel to true and returning from my c# method appears to do nothing. Word still closes. Am I doing something wrong? private void...
0
5407
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 board. I have a form that contains a ListView and a GroupBox control. The GroupBox control itself contains several TextBox Controls. I have Validating and Validated event handlers set for the GroupBox control, and a SelectedIndexChanged event...
3
2770
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 the value to False, but I would have expected it to be False on entry. TIA Charles
6
4952
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 event of a datatable, from two seperate classes. I wish to do some data validating. Due to the nature of the data validation being done, I seperated this code in two classes.
3
9109
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 = false; } else { event.cancelBubble = true
21
9148
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 the cancel button, the textbox.validating is being called. I don't want it to be since they are exiting the screen the validation doesn't have to be done. How can I do that.
4
2990
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 another when its form Closing routine is run? I guess what I'm asking is will that work. If one form sets e.cancelled to true will e.cancel be true when the next form receives a closing event?
3
7646
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, How does the form subsequently know to NOT close the form? More generally, after an event is raised, does the event raising class somehow retain a reference to the CancelEventArgs instance, and then check the value of the .Cancel property to...
0
7874
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
6652
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
5738
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
5404
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
3854
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
3895
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1476
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1205
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.