473,574 Members | 2,701 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>
<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. }
  18. function addListeners(e)
  19. {
  20.   var commissionSchedule = document.getElementById("commissionschedule");
  21.   addEvent(commissionSchedule, 'keyup', setCounter, false);
  22. }
  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. }
  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 4390
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>
<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

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!");
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...
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.
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(){
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...
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...
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
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
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.
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...
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...
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...
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...
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...
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...
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...
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...

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.