|
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 this little script 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
|
|
|
Sorry...figured this out myself, Just extraneous {} were causing it to fail. Thanks anyways.
Vanessa
|
|
|
You also need to get into the practice of terminating your statements with the semicolon.
|
|
|
|
|
Thanks! Do you mean at the end of every line?
Vanessa
|
|
|
Not EVERY line, but every "statement". It's not a technical requirement, as the specification is a bit forgiving. But it's good practice.
So in your code, the "resSize =" statements should, if you're being strict, have terminal semicolons.
|
|
|
|
|
|
|
|
|
© Copyright codetoad.com 2001-2005 |
|
|