SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing A String With Function. Help!

    this is so basic, but I can't figure it out! I have a string "box" that I want passed into my function, but it's not working! If I remove the second variable from being passed, the script works. Here's all the code.

    Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Mouse Coordinates</title>
    
    <script type="text/javascript">
    function SetValues(mouse, div)
    {
      	var mousex = mouse.clientX;
        var mousey = mouse.clientY;
        document.getElementById('box').style.left = mousex;
        document.getElementById('box').style.top = mousey;
    
    }  
    
    </script>
    
    </head>
    
    <body onmousemove=SetValues(event, "box");>
    
    <div id="divCoord"></div>
    
    <div id="box" style='position:absolute; width:100px; height:100px; background-color:red;'>
    </div>
    
    </body>
    </html>
    I live in Madison. Where in the W1RLD do you live?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,687
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    HTML uses double quotes to delimit text, so you need to update the body line to

    Code javascript:
    <body onmousemove="SetValues(event, 'box');">
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •