PDA

View Full Version : Why isnt this working?


GreyBoy
01-18-2006, 12:00 PM
I am trying to change the page background when a img is clicked. Ive tried about 6 different ways, but non seem to work. I think I must be missing something...


<script type="text/javascript">
<!--
function changeBG ( id )
{

if(id == 1){ document.body.backgroundImage = "url(http://files.tagworld.com/81561a514b5870dc4856bacfd1bf11d08fb2.gif)"; }
else if(id == 2){ document.body.backgroundImage = "url(http://files.tagworld.com/cc7605e7a49254594d99bf67d354ad1f7f5d.jpg)"; }
else if (id == 3){ document.bodybody.backgroundImage = "url(http://files.tagworld.com/244dd645e8bea05f4408a63871a6a8684a6e.jpeg)"; }
else{document.body.style.backgroundImage = "url(http://files.tagworld.com/244dd645e8bea05f4408a63871a6a8684a6e.jpeg)"; }

}
//-->
</script>
<p>Choose a background for my page: </p>
<table width="368" cellspacing="0" cellpadding="0">
<tr>
<td width="95"><img src="http://files.tagworld.com/81561a514b5870dc4856bacfd1bf11d08fb2.gif" width="75px" height="75px" id="1" onClick="changeBG(1);" /></td>
<td width="95"><img src="http://files.tagworld.com/cc7605e7a49254594d99bf67d354ad1f7f5d.jpeg" width="75px" height="75px" id="2" onClick="changeBG(2);" /></td>
<td width="96"><img src="http://files.tagworld.com/244dd645e8bea05f4408a63871a6a8684a6e.jpeg" width="75px" height="75px" id="3" onClick="changeBG(3);" /></td>
</tr>
</table>

_Aerospace_Eng_
01-18-2006, 12:21 PM
Check your syntax, you used document.bodybody. I would do it like this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function changeBG(id){
if(id == 1){
document['body'].style.backgroundImage = "url(http://files.tagworld.com/81561a514b5870dc4856bacfd1bf11d08fb2.gif)";
}
else if(id == 2){
document['body'].style.backgroundImage = "url(http://files.tagworld.com/cc7605e7a49254594d99bf67d354ad1f7f5d.jpeg)";
}
else if (id == 3){
document['body'].style.backgroundImage = "url(http://files.tagworld.com/244dd645e8bea05f4408a63871a6a8684a6e.jpeg)";
}
else{
document['body'].style.backgroundImage = "url(http://files.tagworld.com/244dd645e8bea05f4408a63871a6a8684a6e.jpeg)";
}
}
//-->
</script>
</head>

<body>
<p>Choose a background for my page: </p>
<table width="368" cellspacing="0" cellpadding="0">
<tr>
<td width="95"><img src="http://files.tagworld.com/81561a514b5870dc4856bacfd1bf11d08fb2.gif" width="75" height="75" id="1" onClick="changeBG(1);" /></td>
<td width="95"><img src="http://files.tagworld.com/cc7605e7a49254594d99bf67d354ad1f7f5d.jpeg" width="75" height="75" id="2" onClick="changeBG(2);" /></td>
<td width="96"><img src="http://files.tagworld.com/244dd645e8bea05f4408a63871a6a8684a6e.jpeg" width="75" height="75" id="3" onClick="changeBG(3);" /></td>
</tr>
</table>
</body>
</html>
using the square bracket notation.

GreyBoy
01-18-2006, 12:30 PM
Thanks Aero... I knew something looked funny... worked like a charm