By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,569 Members | 1,321 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,569 IT Pros & Developers. It's quick & easy.

Script works in IE 6, but not Firefox -- Need Help!

P: n/a
I'm trying to figure out why this script will work in IE 6 but not
Firefox, and so I need someone here with a far better grasp on
javascript to explain this. Basically, I have a page with several
thumbnails. Above these thumbnails I placed a large picture with text
next to it to describe what the picture is about. So, when you click a
thumb, the large pic AND text change dynamically to reflect the
thumbnail -- see http://www.chadsmoore.com/pjstarhomeless -- for a
live example.

The scripts on my web page are located in the head section. I have
provided the script below . The "while" condition is used to prevent
the text from appending to each other after each click.

This script works perfectly in IE 6, but won't work in Firefox.

Any suggestions to making this work in Firefox would be greatly
appreciated.

Thanks in advance!


// script to change text -- thumbnail 1

function homelessbwWoman(){
while (content.hasChildNodes()) {
content.removeChild(content.lastChild);

}

var txt = 'Tamara Maslanka takes a telephone call for a client at the
Illinois Valley Public Action to Deliver Shelter location in Ottawa.
Maslanka now directs operations at the shelter where she and her family
once lived.';
var txtn= document.createTextNode(txt);
document.getElementById("content").appendChild(txt n);

}
// script to change text -- thumbnail 2

function homelessbwFlorist(){
while (content.hasChildNodes()) {
content.removeChild(content.lastChild);

}

var txt = 'Robert Maslanka puts together a floral arrangement at TPM
Stems in Ottawa. The upscale floral and interior landscape design shop
hired Maslanka while he and his wife resided at the IVPADS shelter. The
job, with hours donated by other employees, helped the Maslankas get on
their feet and out of a homeless situation.';
var txtn= document.createTextNode(txt);
document.getElementById("content").appendChild(txt n);
}


// Change Image Script

function canManipulateImages() {
if (document.images)
return true;
else
return false;
}
function loadHomelesslg(imageURL) {
if (gImageCapableBrowser) {
document.homelessLG.src = imageURL;
return false;
}
else {
return true;
}
}
gImageCapableBrowser = canManipulateImages();


// relevant body code

<tr>
<td width="240">

<!-- Large Image -->

<img src="thumbnails/bwWoman_lg.jpg" height="174" width="240"
id="homelessLG" name="homelessLG" alt="" />

</td>
<td>

<!-- Div element named "content" containing dynamic text -->

<div id="content" class="picContent">
Tamara Maslanka takes a telephone call for a client
at the Illinois Valley Public Action to Deliver Shelter location in
Ottawa. Maslanka now directs operations at the shelter where she and
her family once lived.

</div>
</td>
</tr>

// Two cells each containing clickable thumbnails

<table>
<tr>
<td>
<a href="#" onclick="homelessbwWoman();
return(loadHomelesslg('thumbnails/bwWoman_lg.jpg'));"><IMG
alt=DAILY_PICS-MASLANKA1_BW
src="thumbnails/bwWoman_th.jpg"
width="75" height="56"></a>
</td>
<td>
<a
href="#" onClick="homelessbwFlorist();
return(loadHomelesslg('thumbnails/bwManFloral_lg.jpg'));" ><IMG
alt=DAILY_PICS-MASLANKA3_BW
src="thumbnails/bwManFloral_th.jpg" width="75"
height="56"></a>

</td>
</tr>
</table>

Jul 6 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I think it's because your variable 'content' isn't assigned explicitly.
You need a line
like this that is executed when the document loads
<body onload="content = document.getElementById( 'content' );">
or just place it at the bottom of the page.

<script type="text/javascript">
content = document.getElementById( 'content' );
</script>
</html>

I think IE will attempt to find the element with id 'content' if you
haven't defined it as a variable.

ranger7419 wrote:
I'm trying to figure out why this script will work in IE 6 but not
Firefox, and so I need someone here with a far better grasp on
javascript to explain this. Basically, I have a page with several
thumbnails. Above these thumbnails I placed a large picture with text
next to it to describe what the picture is about. So, when you click a
thumb, the large pic AND text change dynamically to reflect the
thumbnail -- see http://www.chadsmoore.com/pjstarhomeless -- for a
live example.

The scripts on my web page are located in the head section. I have
provided the script below . The "while" condition is used to prevent
the text from appending to each other after each click.

This script works perfectly in IE 6, but won't work in Firefox.

Any suggestions to making this work in Firefox would be greatly
appreciated.

Thanks in advance!


// script to change text -- thumbnail 1

function homelessbwWoman(){
while (content.hasChildNodes()) {
content.removeChild(content.lastChild);

}

var txt = 'Tamara Maslanka takes a telephone call for a client at the
Illinois Valley Public Action to Deliver Shelter location in Ottawa.
Maslanka now directs operations at the shelter where she and her family
once lived.';
var txtn= document.createTextNode(txt);
document.getElementById("content").appendChild(txt n);

}
// script to change text -- thumbnail 2

function homelessbwFlorist(){
while (content.hasChildNodes()) {
content.removeChild(content.lastChild);

}

var txt = 'Robert Maslanka puts together a floral arrangement at TPM
Stems in Ottawa. The upscale floral and interior landscape design shop
hired Maslanka while he and his wife resided at the IVPADS shelter. The
job, with hours donated by other employees, helped the Maslankas get on
their feet and out of a homeless situation.';
var txtn= document.createTextNode(txt);
document.getElementById("content").appendChild(txt n);
}


// Change Image Script

function canManipulateImages() {
if (document.images)
return true;
else
return false;
}
function loadHomelesslg(imageURL) {
if (gImageCapableBrowser) {
document.homelessLG.src = imageURL;
return false;
}
else {
return true;
}
}
gImageCapableBrowser = canManipulateImages();


// relevant body code

<tr>
<td width="240">

<!-- Large Image -->

<img src="thumbnails/bwWoman_lg.jpg" height="174" width="240"
id="homelessLG" name="homelessLG" alt="" />

</td>
<td>

<!-- Div element named "content" containing dynamic text -->

<div id="content" class="picContent">
Tamara Maslanka takes a telephone call for a client
at the Illinois Valley Public Action to Deliver Shelter location in
Ottawa. Maslanka now directs operations at the shelter where she and
her family once lived.

</div>
</td>
</tr>

// Two cells each containing clickable thumbnails

<table>
<tr>
<td>
<a href="#" onclick="homelessbwWoman();
return(loadHomelesslg('thumbnails/bwWoman_lg.jpg'));"><IMG
alt=DAILY_PICS-MASLANKA1_BW
src="thumbnails/bwWoman_th.jpg"
width="75" height="56"></a>
</td>
<td>
<a
href="#" onClick="homelessbwFlorist();
return(loadHomelesslg('thumbnails/bwManFloral_lg.jpg'));" ><IMG
alt=DAILY_PICS-MASLANKA3_BW
src="thumbnails/bwManFloral_th.jpg" width="75"
height="56"></a>

</td>
</tr>
</table>
Jul 6 '06 #2

P: n/a

bobzimuta wrote:
I think it's because your variable 'content' isn't assigned explicitly.
You need a line
like this that is executed when the document loads
<body onload="content = document.getElementById( 'content' );">
or just place it at the bottom of the page.

<script type="text/javascript">
content = document.getElementById( 'content' );
</script>
</html>

I think IE will attempt to find the element with id 'content' if you
haven't defined it as a variable.

Awesome. Problem solved. Thanks a million, bobzimuta!

Jul 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.