I'm running the following function in Firefox. I've thrown the alerts
in to help figure out where the error is. The code terminates at the
line
var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which
: evt.keyCode);
I get no error in the javascript console, the code just stops cold (I
don't get the second alert message).
Do you have any idea why?
function parseDateField( evt) {
evt = (evt) ? evt : ((window.event) ? event : null);
if (evt) {
var elem = (evt.target) ? evt.target : evt.srcElement;
if (elem) {
alert ("break 1");
var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ?
evt.which : evt.keyCode);
alert ("charCode = " + charCode);
return true;
} else {
return false;
}
}
}
Its being called in the body of the page here
<INPUT TYPE="text" NAME="txtDate" id="txtDate" SIZE="9" MAXLENGTH="9"
onkeypress="par seDateField(thi s)"> 1 3265 br**********@wp afb.af.mil wrote: I'm running the following function in Firefox. I've thrown the alerts in to help figure out where the error is. The code terminates at the line var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
No it doesn't. It never gets to that line.
I get no error in the javascript console, the code just stops cold (I don't get the second alert message). Do you have any idea why?
You call this as <INPUT ... onkeypress="par seDateField(thi s)"> so the
- this - keyword in the onkeypress handler of the INPUT element is a
reference to the INPUT element. It is this reference that you pass to
your - parseDateField - function as its - evt - argument.
function parseDateField( evt) { evt = (evt) ? evt : ((window.event) ? event : null);
The - evt - parameter is always a reference to the INPUT element, so it
is true.
if (evt) {
The - evt - parameter is still true here.
var elem = (evt.target) ? evt.target : evt.srcElement;
INPUT elements do not have - target - or - srcElement - properties so
the value assigned to - elem - is undefined.
if (elem) {
Undefined type-coverts to boolean false so this branch of the if-else
is never entered, and the - else - branch is taken.
alert ("break 1"); var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode); alert ("charCode = " + charCode); return true; } else { return false;
The - else - branch just returns false, with no errors generated (or
expected).
} } }
Its being called in the body of the page here <INPUT TYPE="text" NAME="txtDate" id="txtDate" SIZE="9" MAXLENGTH="9" onkeypress="par seDateField(thi s)">
Replace the onkeypress handler with:-
onkeypress="par seDateField(eve nt, this);"
- and add a second parameter to the function to recieve the INPUT
element passed with - this -(saves messing about with
target/srcElement). Or keep passing the - this - and treat the value
that arrives as the reference to the element you want to act upon not
the event object.
Richard. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Thomas Christensen |
last post by:
I'm trying to figure out what key the user pressed using a Danish
keyboard layout. charCodeAt returns the correct number, but
event.keyCode returns a wrong number, when using one of the keys that
are different on a Danish keyboard layout. "-" returns 45 and 189
respectively. Etc. (The input-field in the sample code below displays
the right character).
I've tried setting the lang-parameter to 'da', but it doesn't make a
difference.
|
by: Daniel Walzenbach |
last post by:
Hi,
I have a web application which sometimes throws an “out of memory”
exception. To get an idea what happens I traced some values using performance
monitor and got the following values (for one day):
\\FFDS24\ASP.NET Applications(_LM_W3SVC_1_Root_ATV2004)\Errors During
Execution: 7
\\FFDS24\ASP.NET Apps v1.1.4322(_LM_W3SVC_1_Root_ATV2004)\Compilations
|
by: jh3an |
last post by:
How are you ? :)
This code works on Internet Explorer:
function(event){
event.keyCode = 'a';
}
So, No matter what you typed in the textbox or textarea, you would get
'a'.
|
by: matheussousuke |
last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails.
The goal is: Make it send the email with the URL http://mghospedagem.com/images/controlpanel.jpg
instead of
http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg
As u see, there's the website URL before the image URL.
|
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look !
Part I. Meaning of...
| |
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,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 projectplanning, coding, testing, and deploymentwithout 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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
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...
| |