473,671 Members | 2,209 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code Not Working in Firefox: keyup event

6 New Member
I have a web page with the following items on it:

[HTML]<label for="commission schedule">
Commission Schedule<br />
<span id="charCounter ">1000 characters or less</span>
</label>
<textarea id="commissions chedule" rows="10" cols="40"></textarea>[/HTML]

I'm using a standard javascript addEvent function and am attaching a keyup event to the textarea as follows:

Expand|Select|Wrap|Line Numbers
  1. function addEvent(elm, evType, fn, useCapture)
  2. // cross browser event handling
  3. {
  4.   if (elm.addEventListener)
  5.   {
  6.    elm.addEventListener(evType, fn, useCapture);
  7.    return true;
  8.   } else if (elm.attachEvent)
  9.   {
  10.    var r = elm.attachEvent('on' + evType, fn);
  11.    return r;
  12.   } else
  13.   {
  14.    elm['on' + evType] = fn;
  15.   }
  16. }
  17.  
  18. function addListeners(e)
  19. {
  20.   var commissionSchedule = document.getElementById("commissionschedule");
  21.   addEvent(commissionSchedule, 'keyup', setCounter, false);
  22. }
  23.  
  24. function setCounter() {
  25.     var charCounter = document.getElementById("charCounter");
  26.     var commissionSchedule = document.getElementById("commissionschedule");
  27.     var currentLength = commissionSchedule.value.length;
  28.     var numCharsLeft = 1000 - currentLength;
  29.     var htmlFrag = document.createTextNode("" + numCharsLeft + " characters left");
  30.     while (charCounter.hasChildNodes())
  31.         charCounter.removeChild(charCounter.lastChild);
  32.     charCounter.appendChild(htmlFrag);
  33. }
  34.  
  35. addEvent(window, 'load', addListeners, false);
Now, I've done this a dozen times before (with 'click', though, not 'keyup'), and never had a problem, but in this case, the setCounter function is never called in Firefox. In IE this works perfectly, updating #charCounter with the number of characters left on each keyup event. However, in FF, the setCounter event handler is never even called. I have checked, and setCounter IS getting attached to the onkeyup even handler for the textarea at page load, but never actually fires once the user begins typing.

Any idea? Thanks a ton!
Aug 17 '07 #1
1 4395
mrhoo
428 Contributor
Nothing wrong with your script, its the html- firefox is stricter than IE.
A label can only contain its control element and text. Try this:

[HTML]<p >
<label for="commission schedule">Commi ssion Schedule</label>
<span id="charCounter ">1000 characters or less</span>
</p>
<textarea id="commissions chedule" rows="10" cols="40"></textarea>[/HTML]
Aug 18 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2076
by: CJack | last post by:
hy, I have an mdi application, i create a child form and I want to know when a button is pressed while that child form is loaded. I have this code: private void frmTestBaby_KeyUp(object sender, System.EventArgs e) { MessageBox.Show("keyboard button pressed!");
3
13054
by: Lachlan Hunt | last post by:
Hi, I've been looking up lots of documentation and trying to work out a cross-platform method of capturing a keyboard event and working out which key was pressed. From what I can find, there doesn't appear to be any standardised keyboard event interface other than this DOM 3 Events W3C Working Group Note . However, it is only a note and doesn't appear to be implemented in any browser. Is there another standard that I've missed? The...
1
4489
by: Ori | last post by:
Hi Guys, Here is my problem, but maybe someone can help me with this. Background: 1. Using C#. 2. I'm having a form which the KeyPreview is on (and must stay like this) and I'm implementing some functions on the Key up event of some controls and the form.
7
9601
by: Coder | last post by:
Hi I have the following code in java script, it is not giving proper output in FIREFOX but running fine in IE... can anybody help me out to make this run in FIREFOX . <script language="JavaScript"> var cntlName; var eleTarget = document.getElementById('hiding'); function showOrHide(){
1
6193
by: Frank O'Hara | last post by:
I think I'm losing my mind, granted it is kind of late here so... I'm trying to do some simple validation on the client as keys are pressed. The validation routine works well enough however I can't seem to cancel the event should the validation fail. Well more accurately, I can't cancel the keyup event. When I hook the following routine to the keydown event it works well and an invalidation cancels the event. I'm hooking the...
3
1402
by: Academia | last post by:
If the user types into the TextBox of a combobox it works OK. But if he hold a key down so the letter repeats quickly the code runs into trouble. My questions are: Is it true that an event's code is normally run to completion before another event's code is entered (KeyUp in my case)? If that is true and there are exceptions that let another event start do they include:
3
3822
by: Brent | last post by:
The code below correctly sets an iframe to be editable, and then tries to attach an "onkeyup" event to the iframe. Instead of doing that, however, it generates a cryptic "Object required" error in Explorer 7, and doesn't seem to do anything at all in Firefox. Am I missing something really basic? Thanks for any help. --Brent
1
1583
by: Chris Jobson | last post by:
>I have a canvas which I use for dragging shapes around such as rectangles Add Focusable="True" to the XAML for the PolyLine and Rectangle elements and then when you set the focus to them they will receive the KeyUp events. Chris Jobson
2
19288
by: Tony Johansson | last post by:
Hello! I have created a Control that consist of a label and a textbox.I have called this class ctlLabelTextbox. public partial class ctlLabelTextbox : UserControl { .... } The class that I have created for this purpose is derived from class UserControl.
0
8476
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
8393
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
8914
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...
1
6223
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
5695
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
4224
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...
1
2810
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
2
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1809
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.