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

Herlp with Firefox

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 == "TD"){
document.all(window.event.srcElement.sourceIndex). bgColor = "#3280ff";

Anybody that can give me the change I need for this to work in Firefox?

Thank you :-)

Jul 3 '06 #1
11 4055
Krij wrote:
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 == "TD"){
document.all(window.event.srcElement.sourceIndex). bgColor = "#3280ff";

Anybody that can give me the change I need for this to work in
Firefox?
Not without seeing how this function is being called.

Richard.
Jul 3 '06 #2
Sorry, here's the whole thing:

<html><head><title>JavaScript lessons Work Example</title>
<script language="javascript">
<!--
function chgColor(){
var thistag;
thistag = window.event.srcElement.tagName;
if(thistag == "TD"){
document.all(window.event.srcElement.sourceIndex). bgColor = "#3280ff";
}
}

function chgBack(){
var thistag;
thistag = window.event.srcElement.tagName;
if(thistag == "TD"){
document.all(window.event.srcElement.sourceIndex). bgColor = "#c0c0c0";
}
}
//--></script></head>
<body onmouseover="chgColor()" onmouseout="chgBack()" font
face="verdana" size="3" COLOR="#000000">
<center>
<table border="5" bordercolor="#006400" width="30%">
<tr>
<td>MAY</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td><td>NOT</td><td>&nbsp;</td><td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td><td>&nbsp;</td><td>WORK</td><td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>IN</td>
</tr>
<tr>
<td>FIREFOX</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
</tr></table>

Thanks for answering :-)
Richard Cornford skrev:
Krij wrote:
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 == "TD"){
document.all(window.event.srcElement.sourceIndex). bgColor = "#3280ff";

Anybody that can give me the change I need for this to work in
Firefox?

Not without seeing how this function is being called.

Richard.
Jul 3 '06 #3
Krij wrote:
<snip>
<script language="javascript">
The language attribute is deprecated and the type attribute required in
valid HTML 4, and its use makes the language attribute redundant:-

<script type="text/javascript">
<!--
This 'hide from older browsers' stuff with HTML comment-like structures
is no longer necessary and should not be used.
function chgColor(){
^
Add a formal parameter so that the event can be passed to this
function:-

function chgColor(ev){

var thistag;
thistag = window.event.srcElement.tagName;
if(thistag == "TD"){
document.all(window.event.srcElement.sourceIndex). bgColor = "#3280ff";
}
}
As the event will be passed to the function as an argument there is no
need to reference IE's global event object. Non-IE browsers use the -
target - property to indicate the originator of the event, so:-

var theTag = ev.srcElement || ev.target;
var theTagName = theTag.tagName;
if(theTagName == 'TD'){
theTag.style.backgroundColor = '#3280ff';
}

- but the target may be a text node contained within an TD element so it
might be necessary to chain up the parent nodes until an element node is
encountered:-

function chgColor(ev){
var theTagName , theTag = ev.srcElement || ev.target;
while(theTag && theTag.noteType != 1){
theTag = theTag.parentNode;
}
if(theTag){
theTagName = theTag.tagName;
if(theTagName == 'TD'){
theTag.style.backgroundColor = '#3280ff';
}
}

Also, set the - backgroundColor - property of the element's - style -
object instead of using the deprecated - bgColor - property (unless you
are trying to actively support dinosaurs like Netscape 4).

<snip>
<body onmouseover="chgColor()" onmouseout="chgBack()"
Pass the event object(s) to your function from the event handing
functions:-

<body onmouseover="chgColor(event)" onmouseout="chgBack(event)"

<snip>
Richard Cornford skrev:
<snip>

Please do not top-post to comp.lang.javascript.

Richard.
Jul 3 '06 #4
Hi!

Thank you very much for answering and explaining a novice on javascript
:-)
Not sure what you mean by "do not top-post to..."

Richard Cornford skrev:
Krij wrote:
<snip>
<script language="javascript">

The language attribute is deprecated and the type attribute required in
valid HTML 4, and its use makes the language attribute redundant:-

<script type="text/javascript">
<!--

This 'hide from older browsers' stuff with HTML comment-like structures
is no longer necessary and should not be used.
function chgColor(){
^
Add a formal parameter so that the event can be passed to this
function:-

function chgColor(ev){

var thistag;
thistag = window.event.srcElement.tagName;
if(thistag == "TD"){
document.all(window.event.srcElement.sourceIndex). bgColor = "#3280ff";
}
}

As the event will be passed to the function as an argument there is no
need to reference IE's global event object. Non-IE browsers use the -
target - property to indicate the originator of the event, so:-

var theTag = ev.srcElement || ev.target;
var theTagName = theTag.tagName;
if(theTagName == 'TD'){
theTag.style.backgroundColor = '#3280ff';
}

- but the target may be a text node contained within an TD element so it
might be necessary to chain up the parent nodes until an element node is
encountered:-

function chgColor(ev){
var theTagName , theTag = ev.srcElement || ev.target;
while(theTag && theTag.noteType != 1){
theTag = theTag.parentNode;
}
if(theTag){
theTagName = theTag.tagName;
if(theTagName == 'TD'){
theTag.style.backgroundColor = '#3280ff';
}
}

Also, set the - backgroundColor - property of the element's - style -
object instead of using the deprecated - bgColor - property (unless you
are trying to actively support dinosaurs like Netscape 4).

<snip>
<body onmouseover="chgColor()" onmouseout="chgBack()"

Pass the event object(s) to your function from the event handing
functions:-

<body onmouseover="chgColor(event)" onmouseout="chgBack(event)"

<snip>
Richard Cornford skrev:
<snip>

Please do not top-post to comp.lang.javascript.

Richard.
Jul 3 '06 #5
Hi!

I tried this solution, but it will not work in either FF or IE. Anybody
that can see why?

function chgColor(ev){
var theTagName , theTag = ev.srcElement || ev.target;
while(theTag && theTag.nodeType != 1){
theTag = theTag.parentNode;
}

if(theTag){
theTagName = theTag.tagName;
if(theTagName == 'TD'){
theTag.style.backgroundColor = '#3280ff';
}
}

Likewise I have the same function code for chgChangeColorBack :-)

and in the body tag an onMouseOver and onMouseOut call.
Krij skrev:
Hi!

Thank you very much for answering and explaining a novice on javascript
:-)
Not sure what you mean by "do not top-post to..."

Richard Cornford skrev:
Krij wrote:
<snip>
<script language="javascript">
The language attribute is deprecated and the type attribute required in
valid HTML 4, and its use makes the language attribute redundant:-

<script type="text/javascript">
<!--
This 'hide from older browsers' stuff with HTML comment-like structures
is no longer necessary and should not be used.
function chgColor(){
^
Add a formal parameter so that the event can be passed to this
function:-

function chgColor(ev){

var thistag;
thistag = window.event.srcElement.tagName;
if(thistag == "TD"){
document.all(window.event.srcElement.sourceIndex). bgColor = "#3280ff";
}
}
As the event will be passed to the function as an argument there is no
need to reference IE's global event object. Non-IE browsers use the -
target - property to indicate the originator of the event, so:-

var theTag = ev.srcElement || ev.target;
var theTagName = theTag.tagName;
if(theTagName == 'TD'){
theTag.style.backgroundColor = '#3280ff';
}

- but the target may be a text node contained within an TD element so it
might be necessary to chain up the parent nodes until an element node is
encountered:-

function chgColor(ev){
var theTagName , theTag = ev.srcElement || ev.target;
while(theTag && theTag.noteType != 1){
theTag = theTag.parentNode;
}
if(theTag){
theTagName = theTag.tagName;
if(theTagName == 'TD'){
theTag.style.backgroundColor = '#3280ff';
}
}

Also, set the - backgroundColor - property of the element's - style -
object instead of using the deprecated - bgColor - property (unless you
are trying to actively support dinosaurs like Netscape 4).

<snip>
<body onmouseover="chgColor()" onmouseout="chgBack()"
Pass the event object(s) to your function from the event handing
functions:-

<body onmouseover="chgColor(event)" onmouseout="chgBack(event)"

<snip>
Richard Cornford skrev:
<snip>

Please do not top-post to comp.lang.javascript.

Richard.
Jul 3 '06 #6
Krij wrote:
I tried this solution, but it will not work in either FF or IE. Anybody
that can see why?

function chgColor(ev){
var theTagName , theTag = ev.srcElement || ev.target;
while(theTag && theTag.nodeType != 1){
theTag = theTag.parentNode;
}

if(theTag){
theTagName = theTag.tagName;
if(theTagName == 'TD'){
theTag.style.backgroundColor = '#3280ff';
}
}
}

- missing closing brace (see the reported javascript (syntax) errors in
respective browsers).

<snip>
Richard Cornford skrev:
Krij wrote:
<snip>

Putting your responses above what you quote of previous messages is
top-posting. Please do not do that in comp.lang.javascirpt. see:-

<URL: http://jibbering.com/faq/ >

Richard.

Jul 3 '06 #7


Krij wrote:

and in the body tag an onMouseOver and onMouseOut call.
Have you made the suggested change to pass in the event object to your
functions
<body onmouseover="chgColor(event)" onmouseout="chgBack(event)"

Check the JavaScript console of Firefox whether any script error is
indicated.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 3 '06 #8
Richard Cornford skrev:
Krij wrote:
I tried this solution, but it will not work in either FF or IE. Anybody
that can see why?

function chgColor(ev){
var theTagName , theTag = ev.srcElement || ev.target;
while(theTag && theTag.nodeType != 1){
theTag = theTag.parentNode;
}

if(theTag){
theTagName = theTag.tagName;
if(theTagName == 'TD'){
theTag.style.backgroundColor = '#3280ff';
}
}

}

- missing closing brace (see the reported javascript (syntax) errors in
respective browsers).

<snip>
Richard Cornford skrev:
Krij wrote:
<snip>

Putting your responses above what you quote of previous messages is
top-posting. Please do not do that in comp.lang.javascirpt. see:-

<URL: http://jibbering.com/faq/ >

Richard.
Thank you for clearing up that!

However, I do not get any error in either browsers :-) There are just
two closing brackets, not three. That should just be a typo.

By the way, the book we're using is JS 1.5. Which version are we
'officially' at?

Jul 3 '06 #9
Krij skrev:
Richard Cornford skrev:
Krij wrote:
I tried this solution, but it will not work in either FF or IE. Anybody
that can see why?
>
function chgColor(ev){
var theTagName , theTag = ev.srcElement || ev.target;
while(theTag && theTag.nodeType != 1){
theTag = theTag.parentNode;
}
>
if(theTag){
theTagName = theTag.tagName;
if(theTagName == 'TD'){
theTag.style.backgroundColor = '#3280ff';
}
}
}

- missing closing brace (see the reported javascript (syntax) errors in
respective browsers).

<snip>
Richard Cornford skrev:
Krij wrote:
<snip>

Putting your responses above what you quote of previous messages is
top-posting. Please do not do that in comp.lang.javascirpt. see:-

<URL: http://jibbering.com/faq/ >

Richard.

Thank you for clearing up that!

However, I do not get any error in either browsers :-) There are just
two closing brackets, not three. That should just be a typo.

By the way, the book we're using is JS 1.5. Which version are we
'officially' at?
Hi again!

Sorry, I was wrong :-(

I do get an error in IE. And it's strange. It says: Line 40 Object
expected.

Now this means that in the <BODYtag where I call the function there's
a missing object? However, I have made sure that the correct
onmouseOver contains the correct name of the function, like: <BODY
onmouseover="chgColor(event)" and likewise for the onmouseOut event

so....

it probably mean the error is somewhere else????

Anyway, thank you to all for taking time to solve this :-)

Jul 3 '06 #10
Krij skrev:
Krij skrev:
Richard Cornford skrev:
Krij wrote:
I tried this solution, but it will not work in either FF or IE. Anybody
that can see why?

function chgColor(ev){
var theTagName , theTag = ev.srcElement || ev.target;
while(theTag && theTag.nodeType != 1){
theTag = theTag.parentNode;
}

if(theTag){
theTagName = theTag.tagName;
if(theTagName == 'TD'){
theTag.style.backgroundColor = '#3280ff';
}
}
>
}
>
- missing closing brace (see the reported javascript (syntax) errors in
respective browsers).
>
<snip>
Richard Cornford skrev:
Krij wrote:
<snip>
>
Putting your responses above what you quote of previous messages is
top-posting. Please do not do that in comp.lang.javascirpt. see:-
>
<URL: http://jibbering.com/faq/ >
>
Richard.
Thank you for clearing up that!

However, I do not get any error in either browsers :-) There are just
two closing brackets, not three. That should just be a typo.

By the way, the book we're using is JS 1.5. Which version are we
'officially' at?

Hi again!

Sorry, I was wrong :-(

I do get an error in IE. And it's strange. It says: Line 40 Object
expected.

Now this means that in the <BODYtag where I call the function there's
a missing object? However, I have made sure that the correct
onmouseOver contains the correct name of the function, like: <BODY
onmouseover="chgColor(event)" and likewise for the onmouseOut event

so....

it probably mean the error is somewhere else????

Anyway, thank you to all for taking time to solve this :-)
Hi again!

Just want to be clear on one thing:

In the original posting of code there was an error I think.

It read, in the function:

function chgColor(ev){
var theTagName , theTag = ev.srcElement || ev.target;
while(theTag && theTag.noteType != 1){
theTag = theTag.parentNode;

I changed 'noteType' to 'nodeType'. Was I wrong?

Jul 3 '06 #11


Krij wrote:
By the way, the book we're using is JS 1.5. Which version are we
'officially' at?
For web scripting it should not really matter to you. The scripting
engines in browsers like IE 5.5. and later, Netscape 6 and later,
Firefox 1.0 and later, Opera 7 and later very much support the
ECMAScript edition 3 which defines core language stuff like types,
expressions, statements, objects, functions. Then what matters for web
scripting is the DOM support.

As for the official JavaScript version we are at, Firefox 1.5 supports
JavaScript 1.6, Firefox 2.0 when released later this year is supposed to
support JavaScript 1.7.
But as said, it should not really matter to you unless you specifically
script for Firefox/Mozilla (e.g. XUL, extensions) because most changes
after JavaScript 1.5 are not supported in other browsers' scripting
engines and need to be specifically requested even in Firefox/Mozilla
(e.g. with
<script type="text/javascript; version=1.6">
).
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 3 '06 #12

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

Similar topics

3
by: Jeremy Epstein | last post by:
I've got a 4-page form that lets users enter a whole lot of information, which is then submitted and emailed at the end. All the fields are stored as session data. The whole thing works fine: ...
87
by: expertware | last post by:
Dear friends, My name is Pamela, I know little about CSS, but I would like to ask a question I have an image on a web page within a css layer: <DIV ID=MyLayer STYLE = "position:...
14
by: expertware | last post by:
Ok! to avoid confusion I will start a new argument. Thanks!! FIREFOX 1.0.7 AND IE6 viewed through DATATIME: a summary REPORT ===============================================================...
5
by: SPE - Stani's Python Editor | last post by:
Hi, During optimizing SPE for Ubuntu, I found something strange. I have Ubuntu 5.10 "The Breezy Badger" and unfortunately this code is not working: >>> import webbrowser >>>...
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...
12
by: amit | last post by:
Hello group, I'm kinda skeptical about a code is being used in my js program. All it does is checking what browser is being run and finds out if FLASH is installed or not. This code works...
6
by: scotty | last post by:
I have a script that loops through an existing table list and prepares each href element node to trigger a function when an image is clicked. The function that will be run passes a property value...
7
by: Carlos Mendonça | last post by:
Has anyone managed to get ClickOnce to work with Firefox? It seems to me that it still has the same issues VS 2K5 had. I appreciate any comments or tips.
3
by: SAL | last post by:
Hello, I did google this issue and found some stuff related to BrowserCaps section of either web.config or machine.config but it didn't work. It seems that most pages in my webapp are okay but a...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...
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
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.