473,388 Members | 1,340 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,388 software developers and data experts.

Firefox srcElement Issue

Ok. I have figured out my whole script except how to make it work in
FF. It is a script that lets a user know how many characters they
have left for a textbox. Here is the code, is anyone savy enough to
tell me why this wont work in FF?

Any help would be appreciated. Thank you.

Code:

<script>
function count()
{
var myObject = event.srcElement;
fieldID = myObject.id;
boxtitle = myObject.title;
maximumLength = document.getElementById(boxtitle).maxLength;
var boxtop = myObject.style.top.replace(/px/g, "") * 1;
var boxleft = myObject.style.left.replace(/px/g, "") * 1;
var boxwidth = myObject.style.width.replace(/px/g, "") * 1;

if(document.getElementById(fieldID).value != "")
{
myspan = document.getElementById(fieldID + 'CNT')

charleft = maximumLength -
document.getElementById(fieldID).value.length;
charleft = "" + charleft //convert to string
if (charleft.length == 3) {
myspan.innerText = "Characters left: " + charleft
}

if (charleft.length == 2) {
myspan.innerText = "Characters left: 0" + charleft
}

if (charleft.length == 1) {
myspan.innerText = "Characters left: 00" + charleft
}

myspan.style.top = boxtop - 15
myspan.style.left = boxleft + boxwidth - 107
}

}
</script>
<script>
document.getElementById("TXTAREA01").onkeyup = count;
document.getElementById("TXTAREA02").onkeyup = count;
document.getElementById("TXTAREA03").onkeyup = count;
document.getElementById("TXTAREA04").onkeyup = count;
</script>
<span id = 'TXTAREA01CNT' style='font-family:Arial; font-
weight:Bold ;position: absolute;'></span>
<span id = 'TXTAREA02CNT' style='font-family:Arial; font-
weight:Bold ;position: absolute;'></span>
<span id = 'TXTAREA03CNT' style='font-family:Arial; font-
weight:Bold ;position: absolute;'></span>
<span id = 'TXTAREA04CNT' style='font-family:Arial; font-
weight:Bold ;position: absolute;'></span>

Jun 5 '07 #1
3 6092
On Jun 5, 2:17 pm, Jake G <jgood...@dps.state.oh.uswrote:
Ok. I have figured out my whole script except how to make it work in
FF. It is a script that lets a user know how many characters they
have left for a textbox. Here is the code, is anyone savy enough to
tell me why this wont work in FF?

Any help would be appreciated. Thank you.

Code:

<script>
function count()
{
var myObject = event.srcElement;
fieldID = myObject.id;
boxtitle = myObject.title;
maximumLength = document.getElementById(boxtitle).maxLength;
var boxtop = myObject.style.top.replace(/px/g, "") * 1;
var boxleft = myObject.style.left.replace(/px/g, "") * 1;
var boxwidth = myObject.style.width.replace(/px/g, "") * 1;

if(document.getElementById(fieldID).value != "")
{
myspan = document.getElementById(fieldID + 'CNT')

charleft = maximumLength -
document.getElementById(fieldID).value.length;
charleft = "" + charleft //convert to string

if (charleft.length == 3) {
myspan.innerText = "Characters left: " + charleft
Google this group for 'innerText'

---
Geoff

Jun 5 '07 #2
On Jun 5, 2:33 pm, Geoffrey Summerhayes <sumr...@gmail.comwrote:
On Jun 5, 2:17 pm, Jake G <jgood...@dps.state.oh.uswrote:
Ok. I have figured out my whole script except how to make it work in
FF. It is a script that lets a user know how many characters they
have left for a textbox. Here is the code, is anyone savy enough to
tell me why this wont work in FF?
Any help would be appreciated. Thank you.
Code:
<script>
function count()
{
var myObject = event.srcElement;
fieldID = myObject.id;
boxtitle = myObject.title;
maximumLength = document.getElementById(boxtitle).maxLength;
var boxtop = myObject.style.top.replace(/px/g, "") * 1;
var boxleft = myObject.style.left.replace(/px/g, "") * 1;
var boxwidth = myObject.style.width.replace(/px/g, "") * 1;
if(document.getElementById(fieldID).value != "")
{
myspan = document.getElementById(fieldID + 'CNT')
charleft = maximumLength -
document.getElementById(fieldID).value.length;
charleft = "" + charleft //convert to string
if (charleft.length == 3) {
myspan.innerText = "Characters left: " + charleft

Google this group for 'innerText'

---
Geoff
Also Google it for 'event'

-Jason

Jun 5 '07 #3
On Jun 6, 4:17 am, Jake G <jgood...@dps.state.oh.uswrote:
Ok. I have figured out my whole script except how to make it work in
FF. It is a script that lets a user know how many characters they
have left for a textbox. Here is the code, is anyone savy enough to
tell me why this wont work in FF?

Any help would be appreciated. Thank you.

Code:

<script>
function count()
{
var myObject = event.srcElement;
Firefox (and other browsers) impelement the W3C event model, which is
different to to IE's. When you attach an event handler the way you
have, Firefox will pass a reference to the event object as the first
argument.

You might find the following useful:

<URL: http://www.quirksmode.org/js/introevents.html >
Also, the W3C equivalent to srcElement is target, so to get cross
browser compatability:

function count(evt) {
var evt = evt || event;
var myObject = evt.target || evt.srcElement;
However, based on how you are attaching the handler, you can avoid all
those issues using:

var myObject = this;

fieldID = myObject.id;
boxtitle = myObject.title;
maximumLength = document.getElementById(boxtitle).maxLength;
var boxtop = myObject.style.top.replace(/px/g, "") * 1;
To convert a value like "10px" to an integer, use parseInt:

var boxtop = parseInt(myObject.style.top, 10);

If top has been specified as em or %, the above may not function
correctly in some browsers.

var boxleft = myObject.style.left.replace(/px/g, "") * 1;
var boxwidth = myObject.style.width.replace(/px/g, "") * 1;

if(document.getElementById(fieldID).value != "")
{
myspan = document.getElementById(fieldID + 'CNT')

charleft = maximumLength -
document.getElementById(fieldID).value.length;
charleft = "" + charleft //convert to string

if (charleft.length == 3) {
myspan.innerText = "Characters left: " + charleft
}

if (charleft.length == 2) {
myspan.innerText = "Characters left: 0" + charleft
}

if (charleft.length == 1) {
myspan.innerText = "Characters left: 00" + charleft
}
You can probably write a padding function in a couple of lines rather
than lots of sequential if's. At the very least, join them with
'else' clauses so only one is tested.

e.g.

function pad(x, n) {
x = ''+x;
while (x.length < n) {x = '0'+x}
return x;
}
myspan.style.top = boxtop - 15
myspan.style.left = boxleft + boxwidth - 107
The value for top and left must be a length, which requires a unit
(I'll guess you want px):

myspan.style.top = (boxtop - 15) +'px';
myspan.style.left = (boxleft + boxwidth - 107) + 'px';
<URL: http://www.w3.org/TR/CSS21/syndata.h...lue-def-length >
}

}

</script>

<script>
document.getElementById("TXTAREA01").onkeyup = count;
document.getElementById("TXTAREA02").onkeyup = count;
document.getElementById("TXTAREA03").onkeyup = count;
document.getElementById("TXTAREA04").onkeyup = count;
Given way you are using the event object, you could put the onkeyup
event on some parent of the textarea elements and just let the event
bubble up. Otherwise, just use 'this' inside the function to refer to
the target/srcElement and forget the cross-browser issues.
</script>

<span id = 'TXTAREA01CNT' style='font-family:Arial; font-
weight:Bold ;position: absolute;'></span>
While CSS is not case sensitive (but must comply with the case
sensitivity of things outside its control like ID values, XML tag
names, etc.), it is usual to write values in lower case.
--
Rob

Jun 6 '07 #4

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

Similar topics

5
by: Jeff Thies | last post by:
I have this IE specific bit of code for finding the originating node: var obj=window.event.srcElement; How do I do that cross browser (Opera, NS, Safari...)? Is there a standard DOM method? ...
3
by: coolsti | last post by:
Can someone help me enhance this code snippet which works only for IE so that it will also work for Firefox? I have been trying all sorts of things and have gotten to where I can capture the...
6
by: LAshooter | last post by:
I'm trying to use a javascript function that works in IE but not in Firefox. Is there something about this code that is IE specific? If so, can I add/alter something to make it work in more...
11
by: Robert | last post by:
Hi, My previous thread on this topic was too short on information so I I'll try again. When I tried out Firefox 1.5 beta some of my javascript did not work anymore. Here is some code to...
7
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...
11
by: Krij | last post by:
Hi! Here's a training case at school. The function will animate a table cell in IE: function chgColor(){ var thistag, parenttag; thistag = window.event.srcElement.tagName; if(thistag ==...
2
by: jpk872 | last post by:
i created some javascript DHTML that highlights which menu selection the mouse is currently at, but it won't work on Firefox. Any idea? The source is old, so probably things have changed. ...
1
by: xtremebass | last post by:
Hello Bytes, i have a calender program which is created by using Javascript. when i execute that program using Internet Explorer,it works properly but when i tried in Mozilla firefox it didnt...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.