...

View Full Version : Javascript split into HEAD and BODY doesn't work



vanessa19
03-05-2005, 02:12 AM
Hi all,

I am attempting to learn something here.

I have a javscript that works fine when I put it in the BODY of my page:




var resSize

if (screen.width < 690)
{
resSize = "640x480"
}
else if (screen.width < 850)
{
resSize = "800x600"
}
else if (screen.width < 1079)
{
resSize = "1024x768"
}
else if (screen.width < 1200)
{
resSize = "1152x864"
}
else if (screen.width < 1330)
{
resSize = "1280x960"
}
else if (screen.width >= 1600)
{
resSize = "1600x1200"
}
{
document.write('<a href="thispage_' + resSize + '.html">')
}



However, I need to use the document.write method multiple times on the page, so, to make things more concise, I'd like to separate the script into two :

In the HEAD of my page:






var resSize

if (screen.width < 690)
{
resSize = "640x480"
}
else if (screen.width < 850)
{
resSize = "800x600"
}
else if (screen.width < 1079)
{
resSize = "1024x768"
}
else if (screen.width < 1200)
{
resSize = "1152x864"
}
else if (screen.width < 1330)
{
resSize = "1280x960"
}
else if (screen.width >= 1600)
{
resSize = "1600x1200"
}



And in the BODY of my page:






{
document.write('<a href="thispage_' + resSize + '.html">')
}



However, if I do that, nothing seems to happen at all. What am I doing wrong?

Thanks,

Vanessa

hemebond
03-05-2005, 02:22 AM
Your script is contained within script tags?

vanessa19
03-05-2005, 05:06 AM
Yes, of course... sorry.

Vanessa

vanessa19
03-05-2005, 05:59 AM
Hey all,

I found my own solution. Just picky syntax stuff. Unneeded {} braces and stuff.

Thanks anyways,

Vanessa



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum