HighDots Forums  

Why will this Function work in I.E. but not in Firefox?

Javascript JavaScript language (comp.lang.javascript)


Discuss Why will this Function work in I.E. but not in Firefox? in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Dru
 
Posts: n/a

Default Why will this Function work in I.E. but not in Firefox? - 04-04-2004 , 12:26 PM






Am I missing something simple? I can't figure this one out...

<script language="JavaScript" type="text/javascript">
function showDesc(desc)
{
showDescription.innerText = desc;
}
</script>

<img src="images/products/item1.gif)#" width="75" height="75"
border="0" onMouseOver="showDesc('prodName');"
onMouseOut="showDesc('Mouse over image for product name')">

thnx in advance..



Reply With Quote
  #2  
Old   
Evertjan.
 
Posts: n/a

Default Re: Why will this Function work in I.E. but not in Firefox? - 04-04-2004 , 12:33 PM






Dru wrote on 04 apr 2004 in comp.lang.javascript:

Quote:
Am I missing something simple? I can't figure this one out...

script language="JavaScript" type="text/javascript"
function showDesc(desc)
{
showDescription.innerText = desc;
}
/script

img src="images/products/item1.gif)#" width="75" height="75"
border="0" onMouseOver="showDesc('prodName');"
onMouseOut="showDesc('Mouse over image for product name')"

Is showDescription a global variable pointing to a html container?

Only under IE, I suppose.

If it is an ID, first make a variable:

var showDescription = getElementById("showDescription")

[knowing nothing about "Firefox", btw]


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Reply With Quote
  #3  
Old   
Lasse Reichstein Nielsen
 
Posts: n/a

Default Re: Why will this Function work in I.E. but not in Firefox? - 04-04-2004 , 12:59 PM



Dru <Dontemailme (AT) comcast (DOT) net> writes:

Quote:
Am I missing something simple? I can't figure this one out...
You are missing two simple things (and the standard completely).

Quote:
script language="JavaScript" type="text/javascript"
(The language attribute is not needed, but is not incorrect in
HTML 4 Transitional).

Quote:
function showDesc(desc)
{
showDescription.innerText = desc;
You are using a (probably global) variable called "showDescription".
If you haven't declared it, it won't be there in FireFox (or many
other browsers). I guess you want it to refer to an element with
the name or id "showDescription". IE creates variables referring
to named elements, but it's not part of any standard, and many
other browsers don't. It's a FAQ entry:
<URL:http://jibbering.com/faq/#FAQ4_41>

You also use the property "innerText", which is a proprietary IE
feature. It won't work in most other browsers, including FireFox.

You can either use the more widely implemented, but just as
proprietary, innerHTML property, or you can use W3C DOM methods.
<URL:http://jibbering.com/faq/#FAQ4_15>

/L
--
Lasse Reichstein Nielsen - lrn (AT) hotpop (DOT) com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'


Reply With Quote
  #4  
Old   
Michael Winter
 
Posts: n/a

Default Re: Why will this Function work in I.E. but not in Firefox? - 04-04-2004 , 01:07 PM



On 04 Apr 2004 16:33:00 GMT, Evertjan. <exjxw.hannivoort (AT) interxnl (DOT) net>
wrote:

[snip]

Quote:
If it is an ID, first make a variable:

var showDescription = getElementById("showDescription")
You forgot to qualify the method with "document.". The call will error
without it.

Mike

--
Michael Winter
M.Winter (AT) blueyonder (DOT) co.invalid (replace ".invalid" with ".uk" to reply)


Reply With Quote
  #5  
Old   
Dru
 
Posts: n/a

Default Re: Why will this Function work in I.E. but not in Firefox? - 04-04-2004 , 01:10 PM



yeah i neglected to say i had a <div align="center"
id="showDescription"></div>

I'll try the innerHTML and see how that works out

On Sun, 04 Apr 2004 18:59:49 +0200, Lasse Reichstein Nielsen
<lrn (AT) hotpop (DOT) com> wrote:

Quote:
Dru <Dontemailme (AT) comcast (DOT) net> writes:

Am I missing something simple? I can't figure this one out...

You are missing two simple things (and the standard completely).

script language="JavaScript" type="text/javascript"

(The language attribute is not needed, but is not incorrect in
HTML 4 Transitional).

function showDesc(desc)
{
showDescription.innerText = desc;

You are using a (probably global) variable called "showDescription".
If you haven't declared it, it won't be there in FireFox (or many
other browsers). I guess you want it to refer to an element with
the name or id "showDescription". IE creates variables referring
to named elements, but it's not part of any standard, and many
other browsers don't. It's a FAQ entry:
URL:http://jibbering.com/faq/#FAQ4_41

You also use the property "innerText", which is a proprietary IE
feature. It won't work in most other browsers, including FireFox.

You can either use the more widely implemented, but just as
proprietary, innerHTML property, or you can use W3C DOM methods.
URL:http://jibbering.com/faq/#FAQ4_15

/L


Reply With Quote
  #6  
Old   
Evertjan.
 
Posts: n/a

Default Re: Why will this Function work in I.E. but not in Firefox? - 04-04-2004 , 01:19 PM



Michael Winter wrote on 04 apr 2004 in comp.lang.javascript:

Quote:
var showDescription = getElementById("showDescription")

You forgot to qualify the method with "document.". The call will error
without it.

Right.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Reply With Quote
  #7  
Old   
Dru
 
Posts: n/a

Default Re: Why will this Function work in I.E. but not in Firefox? - 04-04-2004 , 01:26 PM




this is inside a .js file so the <script language="javascript"> isn't
needed.

there is a div called showDescription that I left out of my first post
... changing the innerText to innerHTML doesn't seem to help Firefox.
I'm just going to have to read up on the FAQs and probable a good JS
book.

On Sun, 04 Apr 2004 18:59:49 +0200, Lasse Reichstein Nielsen
<lrn (AT) hotpop (DOT) com> wrote:

Quote:
Dru <Dontemailme (AT) comcast (DOT) net> writes:

Am I missing something simple? I can't figure this one out...

You are missing two simple things (and the standard completely).

script language="JavaScript" type="text/javascript"

(The language attribute is not needed, but is not incorrect in
HTML 4 Transitional).

function showDesc(desc)
{
showDescription.innerText = desc;

You are using a (probably global) variable called "showDescription".
If you haven't declared it, it won't be there in FireFox (or many
other browsers). I guess you want it to refer to an element with
the name or id "showDescription". IE creates variables referring
to named elements, but it's not part of any standard, and many
other browsers don't. It's a FAQ entry:
URL:http://jibbering.com/faq/#FAQ4_41

You also use the property "innerText", which is a proprietary IE
feature. It won't work in most other browsers, including FireFox.

You can either use the more widely implemented, but just as
proprietary, innerHTML property, or you can use W3C DOM methods.
URL:http://jibbering.com/faq/#FAQ4_15

/L


Reply With Quote
  #8  
Old   
DU
 
Posts: n/a

Default Re: Why will this Function work in I.E. but not in Firefox? - 04-04-2004 , 01:36 PM



Lasse Reichstein Nielsen wrote:

Quote:
Dru <Dontemailme (AT) comcast (DOT) net> writes:


Am I missing something simple? I can't figure this one out...


You are missing two simple things (and the standard completely).


script language="JavaScript" type="text/javascript"


(The language attribute is not needed, but is not incorrect in
HTML 4 Transitional).


function showDesc(desc)
{
showDescription.innerText = desc;


You are using a (probably global) variable called "showDescription".
If you haven't declared it, it won't be there in FireFox (or many
other browsers). I guess you want it to refer to an element with
the name or id "showDescription". IE creates variables referring
to named elements, but it's not part of any standard, and many
other browsers don't. It's a FAQ entry:
URL:http://jibbering.com/faq/#FAQ4_41

You also use the property "innerText", which is a proprietary IE
feature. It won't work in most other browsers, including FireFox.

You can either use the more widely implemented, but just as
proprietary, innerHTML property, or you can use W3C DOM methods.
URL:http://jibbering.com/faq/#FAQ4_15

/L
That FAQ item does not cover the W3C DOM method. When the node to
change, to update, to modify, etc.. is a text node, there is no W3C DOM
methods explained in the FAQ. Here, knowing more about the OP's page and
specifics, it would have been possible to suggest an entirely W3C
compliant code and cross-browser code like possibly:

<script type="text/javascript">
function showDesc(newDescriptiveText)
{
document.getElementById("showDescription").childNo des[0].nodeValue
= newDescriptiveText ;
}
</script>

<img src="images/products/item1.gif" width="75" height="75"
onmouseover="showDesc('prodName');" onmouseout="showDesc('Mouse over
image for product name');" alt="Descriptive alternate text">

and who knows,

<img src="images/products/item1.gif)#" width="75" height="75"
title="Mouse over image for product name" alt="Descriptive alternate
text">

could have been more than sufficient ... if we only had known what was
the webpage context.

DU


Reply With Quote
  #9  
Old   
Michael Winter
 
Posts: n/a

Default Re: Why will this Function work in I.E. but not in Firefox? - 04-04-2004 , 01:52 PM



On Sun, 04 Apr 2004 17:26:52 GMT, Dru <Dontemailme (AT) comcast (DOT) net> wrote:

[snip]

Quote:
there is a div called showDescription that I left out of my first post
.. changing the innerText to innerHTML doesn't seem to help Firefox.
Because that wasn't the only issue addressed in Lasse's post. The problem
of using an element's id attribute value as a global variable is also a
problem.

Quote:
I'm just going to have to read up on the FAQs and probable a good JS
book.
That would be a good idea.

Mike

[snipped top-post quotation]

--
Michael Winter
M.Winter (AT) blueyonder (DOT) co.invalid (replace ".invalid" with ".uk" to reply)


Reply With Quote
  #10  
Old   
DU
 
Posts: n/a

Default Re: Why will this Function work in I.E. but not in Firefox? - 04-04-2004 , 02:05 PM



Dru wrote:
Quote:
this is inside a .js file so the <script language="javascript"> isn't
needed.

You still need to use the proper attribute when embedding an external
..js file:

<script type="text/javascript" href="path/filename.js"></script>

Quote:
there is a div called showDescription that I left out of my first post
... changing the innerText to innerHTML doesn't seem to help Firefox.
Evertan suggested to you to use the getElementById method which is
widely supported by browsers (MSIE 5+) and is W3C compliant.

Quote:
I'm just going to have to read up on the FAQs and probable a good JS
book.

2 urls I recommend to first visit (which are mentioned in the
comp.lang.javascript FAQ):

Using Web Standards in Your Web Pages
http://www.mozilla.org/docs/web-deve...upgrade_2.html

Updating DHTML Web Pages for next generation browsers
http://devedge.netscape.com/viewsour...tml-web-pages/

These 2 urls have tips and tricks and fit well your questions and
difficulties.

DU

Quote:
On Sun, 04 Apr 2004 18:59:49 +0200, Lasse Reichstein Nielsen
lrn (AT) hotpop (DOT) com> wrote:


Dru <Dontemailme (AT) comcast (DOT) net> writes:


Am I missing something simple? I can't figure this one out...

You are missing two simple things (and the standard completely).


script language="JavaScript" type="text/javascript"

(The language attribute is not needed, but is not incorrect in
HTML 4 Transitional).


function showDesc(desc)
{
showDescription.innerText = desc;

You are using a (probably global) variable called "showDescription".
If you haven't declared it, it won't be there in FireFox (or many
other browsers). I guess you want it to refer to an element with
the name or id "showDescription". IE creates variables referring
to named elements, but it's not part of any standard, and many
other browsers don't. It's a FAQ entry:
URL:http://jibbering.com/faq/#FAQ4_41

You also use the property "innerText", which is a proprietary IE
feature. It won't work in most other browsers, including FireFox.

You can either use the more widely implemented, but just as
proprietary, innerHTML property, or you can use W3C DOM methods.
URL:http://jibbering.com/faq/#FAQ4_15

/L



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.