PDA

View Full Version : Simple error check


wuffy77
10-17-2007, 03:28 PM
Can anyone spot why the below code doesn't work? I've got a working version made by Coothead, and I've then written a VBA script that effectively generates the code for multiple pages, however for some reason the javascript rollovers doesn't work here?!

I've sat and compared side by side and can't spot the difference :mad:

Apologies for the batty formatting, that's Excel VBA for you (could that be an issue?!?)

Edit: I should probably add that I've installed and tried firebug and it says:

missing ; before statement
[Break on this error] gth;c++) {anc[c].onmouseover=function() {swapImage(this.href);}}}function swapIm...

if that makes sense to anyone with a brain?!


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title></title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link rel="stylesheet" type="text/css" href="../../css/preview.css">
<script type="text/javascript">var preload=new Array('../../../Textures/color/armor006_colo.png','../../../Textures/bump/armor006_bump.png','../../../Textures/normal/armor006_norm.png','../../../Textures/displacement/armor006_disp.png','../../../Textures/specular/armor006_spec.png','../../../Textures/opacity/armor006_opac.png');var loader=new Array();for(i= 0;i< preload.length;i++){loader[i]=new Image();loader[i].src=preload[i];}window.onload=function() {anc=document.getElementById('imglist').getElementsByTagName('a');for(c=0;c<anc.length;c++) {anc[c].onmouseover=function() {swapImage(this.href);}}}function swapImage(pic) {document.getElementById('targetImg').src=pic;document.getElementById('targetImg').parentNode.href=p ic;}</script>
</head><body><table><tr><td><h1>Filename: armor006.png</h1></td></tr><tr><td colspan=2><p>Please wait for a few seconds as the high resolution texture loads.<br><br>Hover over the right menu items to preview maps, click menu item to view full size.</p></td></tr><tr><div><td id="target"><a href="image1.jpg"/><img id="targetImg" src="../../../Textures/color/armor006_colo.png" alt=""/></a></td></div><td align="left" valign="top"><ul id="imglist" name="imglist">
<li><a href="../../../Textures/color/armor006_colo.png">Color</a></li><li><a href="../../../Textures/bump/armor006_bump.png">Bump</a></li><li><a href="../../../Textures/normal/armor006_norm.png">Normal</a></li><li><a href="../../../Textures/displacement/armor006_disp.png">Displacement</a></li><li><a href="../../../Textures/specular/armor006_spec.png">Specular</a></li><li><a href="../../../Textures/opacity/armor006_opac.png">Opacity</a></li></ul></td></tr></table></body></html>

diades
10-17-2007, 04:10 PM
Hi

I think that it is the script-scrunching, I spread it out in an editor and it shows no errors.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../../css/preview.css">
<script type="text/javascript">
var preload = new Array('../../../Textures/color/armor006_colo.png',
'../../../Textures/bump/armor006_bump.png',
'../../../Textures/normal/armor006_norm.png',
'../../../Textures/displacement/armor006_disp.png',
'../../../Textures/specular/armor006_spec.png',
'../../../Textures/opacity/armor006_opac.png');
var loader=new Array();
for(i= 0;i< preload.length;i++)
{
loader[i]=new Image();
loader[i].src = preload[i];
}
window.onload = function()
{
anc=document.getElementById('imglist').getElementsByTagName('a');
for(c=0;c<anc.length;c++)
{
anc[c].onmouseover = function()
{
swapImage(this.href);
}
}
}
function swapImage(pic)
{
document.getElementById('targetImg').src=pic;
document.getElementById('targetImg').parentNode.href=pic;
}
</script>
</head>
<body>
<table ID="Table1">
<tr>
<td><h1>Filename: armor006.png</h1>
</td>
</tr>
<tr>
<td colspan="2"><p>Please wait for a few seconds as the high resolution texture
loads.<br>
<br>
Hover over the right menu items to preview maps, click menu item to view full
size.</p>
</td>
</tr>
<tr>
<div><td id="target"><a href="image1.jpg" /><img id="targetImg" src="../../../Textures/color/armor006_colo.png" alt="" /></a></td>
</div>
<td align="left" valign="top"><ul id="imglist" name="imglist">
<li>
<a href="../../../Textures/color/armor006_colo.png">Color</a></li><li><a href="../../../Textures/bump/armor006_bump.png">Bump</a></li><li><a href="../../../Textures/normal/armor006_norm.png">Normal</a></li><li><a href="../../../Textures/displacement/armor006_disp.png">Displacement</a></li><li><a href="../../../Textures/specular/armor006_spec.png">Specular</a></li><li><a href="../../../Textures/opacity/armor006_opac.png">Opacity</a></li></ul>
</td>
</tr>
</table>
</body>
</html>

wuffy77
10-17-2007, 04:24 PM
is there a way I can fix this then? I'm not sure why scrunching should cause an issue?!

Do I need to add a ; somewhere to break the code properly - I know javascript is fairly flexible with it's formatting, so I may need to specify more?!

diades
10-17-2007, 07:50 PM
Whilst js is 'flexible' I think that it would be best to end each line with a semi-colon prior to scrunching :) That does not mean:
if(this){ ;
dothis;
}else{;
dothat;
};
just those that need it :)
It is a good habit to form anyway.