codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  How to separate a javscript into HEAD and BODY, global variable  vanessa19 at 17:22 on Friday, March 04, 2005
 

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

  Re: How to separate a javscript into HEAD and BODY, global variable  vanessa19 at 05:53 on Saturday, March 05, 2005
 

Sorry...figured this out myself, Just extraneous {} were causing it to fail. Thanks anyways.

Vanessa

  Re: How to separate a javscript into HEAD and BODY, global variable  tgreer at 20:15 on Monday, March 07, 2005
 

You also need to get into the practice of terminating your statements with the semicolon.


  Re: How to separate a javscript into HEAD and BODY, global variable  vanessa19 at 01:10 on Wednesday, March 09, 2005
 

Thanks! Do you mean at the end of every line?

Vanessa

  Re: How to separate a javscript into HEAD and BODY, global variable  tgreer at 02:27 on Wednesday, March 09, 2005
 

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.










CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: Collapsable dhtml
•  how to extract search engine results
•  Re: Getting System Information...
•  How do I automate a process using Perl Script
•  callling command prompt utility from VB script
•  Allocate Memory
•  Re: Help: Trouble with z-Index and SELECT lists
•  Removing/Escaping apostrophe in Name column using XSL.
•  Re: Refresh parent page


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005