SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Zealot Marek Bereza's Avatar
    Join Date
    Sep 2001
    Location
    London
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript into html tags

    If I've got a variable, say x, how can I get that into a html tag as a parameter?
    Basically I want to get the position of the top corner of a layer to be determined in the <HEAD>, and then in the body, have <div id="1234" style="position:absolute; left:"x" px; top:"y" px>

    If you see what I mean. Thanks again,

    Marek
    of the brethren of disco metal
    Disco metal tunes at www.wikid.co.uk

  2. #2
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try doing this...

    Within the head section

    function display(){
    document.write("<div id="test" style='left:"+x+"; top:"+y+"; position:absolute>")
    document.write("this is whats in the layer")
    document.write("</div>")
    }

    I think that is what you mean...hope that helps...
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  3. #3
    I am the night... bman's Avatar
    Join Date
    Mar 2001
    Location
    In a van... down by the river.
    Posts
    366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Maelstrom
    Try doing this...

    Within the head section

    function display(){
    document.write("<div id="test" style='left:"+x+"; top:"+y+"; position:absolute>")
    document.write("this is whats in the layer")
    document.write("</div>")
    }

    I think that is what you mean...hope that helps...
    you are going to need to change the quotes around test ("test") to single quotes ('test'). Might cause some problems if you don't. and you will need a single quote after position:absolute (position:abosolute').
    so i think this is what you will need.

    Code:
          document.write("<div id='test' style='left:"+x+"; top:"+y+"; position:absolute'>")
          document.write("this is whats in the layer")
          document.write("</div>")
    Some say the world will end in fire, Some say in ice.
    From what I've tasted of desire
    I hold with those who favor fire.

  4. #4
    SitePoint Zealot Marek Bereza's Avatar
    Join Date
    Sep 2001
    Location
    London
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've already worked it out. Sorry I didn't say so before. Basically I did what you guys said, but didn't think you could do it at first. That's why I didn't try it. I thought you would have to get the details on the clientside, and then change the html serverside, but it works any way.
    Code:
    window.document.writeln('<div id="main" style="position:absolute; left:'+x+'px; top:'+y+'px; width:750px; height:440px; z-index:20">')
    Thanks anyways
    of the brethren of disco metal
    Disco metal tunes at www.wikid.co.uk


Bookmarks

Posting Permissions

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