Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript split into HEAD and BODY doesn't work

    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

  • #2
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Your script is contained within script tags?
    Forget style. Code to semantics. Seperate style from structure, and structure from behaviour.
    I code to specs, and test only in Firefox (unless stated otherwise).

  • #3
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, of course... sorry.

    Vanessa

  • #4
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Hey all,

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

    Thanks anyways,

    Vanessa


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •