473,406 Members | 2,619 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,406 software developers and data experts.

How to onkeypress work on Mozilla Firefox?

ariful alam
185 100+
I tried to code a javascript that will count the characters written in a text box and show in a div tag. To do this i used <code>onkeypress</code> in my text box. The code is working in Internet Explorer 6, Opera 10.60 and GOOGLE Chrome. But not in Mozilla Firefox 3.6.13. The code is given below. Please, help.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4.  
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <title>script</title>
  8. <script language="javascript" type="text/javascript">
  9. function counter(val)
  10. {
  11.     document.getElementById('c').innerText=document.getElementById(val).value.length;
  12. }
  13. </script>
  14. </head>
  15. <body>
  16.  
  17. <input type="text" id="txt" name="txt" onkeypress="counter('txt')"/><div id="c"></div>
  18.  
  19. </body>
  20. </html>
  21.  
  22.  
Thanks
Jan 19 '11 #1

✓ answered by Dormilich

innerText is proprietary to IE. the DOM-compliant property is named textContent. the best compromise is probably innerHTML

2 2016
Dormilich
8,658 Expert Mod 8TB
innerText is proprietary to IE. the DOM-compliant property is named textContent. the best compromise is probably innerHTML
Jan 19 '11 #2
ariful alam
185 100+
@Dormilich:

Thanks :)
innerHTML is working on the 4 browsers correctly, i mentioned.


Ok, I need another help. I need a div tag for the above code. Think the input object has maxLength=25. When I type 25 characters in that input box, a div will flashed for 3 seconds and hides automatically after 3seconds. What should I do to solve this matter.

Thanks again!!!!
Jan 20 '11 #3

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

Similar topics

4
by: ekimnosnews | last post by:
I'm programming a JS tile map editor for my friend's game. The map editor has different "sections" that contain different tiles. The way that it works is when you select a section it calls a JS...
2
by: Eli | last post by:
Hi, Since using IFRAMEs in my page, I want to disable the F5 and BackSpace keys. I got this working on IE but not on Mozilla Firefox: function CheckKey(evt) { evt=(evt)?evt:window.event;...
0
by: z0rr0 | last post by:
Anybody noticed problem with getting MoinMoin external file URL to work with Mozilla/Firefox? for example - or or all work OK with Internet Exploder but not with Firefox!
0
by: BACON | last post by:
I'm just starting the process of reorganising my modest little website and cleaning up all the HTML, and the logical place to begin was with the homepage. I made a simple little ASP.NET control...
8
by: Clément | last post by:
Hi! I am currently developping a user interface with Ajax/C#/.net. And I am facing a problem with Mozilla, and Firefox. I use the function innerHTML to load a Web UserControl into a div, this...
11
by: minnesotti | last post by:
Hi there, I subscribed to a photographic pictures-hosting website which is heavy on JavaScript. My preferred latest browser Mozilla Firefox does not work with it -- no pictures are displayed and...
3
by: Mufasa | last post by:
Can anybody suggest websites that talk about what you need to do to make an IE site also work under Firefox. What things are allowed and what aren't - that type of thing. TIA - Jeff.
4
by: Eo | last post by:
Hey I hav JS code that expend TD if beeing click on from some reson it dose not work in firefox(won't open) just under IE it works any Idea? function MoreInfo(id) { AId=id; FullPage ="<?...
2
by: sajithamol | last post by:
How can i migrate one application from IE to Mozilla Firefox. while working in IE , javascript was working perfectly . But when i used Mozilla firefox , javascript not working. How can i make one...
5
by: hannie | last post by:
onKeyPress does not work in Firefox. If use tab to navigate each field and press "Enter" on "Next" button to submit form and process to the next form / page, IE works well even if without onKeyPress...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
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,...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.