SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: DHTML problems

  1. #1
    SitePoint Member
    Join Date
    Jul 2001
    Location
    New Orleans, LA
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    DHTML problems

    I was tinkering with this DHTML code, trying to practice and learn, but for some reason it won't work. It's IE-specific, and in it the button's supposed to move to a random location whenever you mouse over, and if you ever manage to click it, the text changes to congratulate you.
    ------------------------------------------
    moving_button.html
    ------------------------------------------
    <HTML>
    <HEAD>
    <STYLE>
    #text {font-family:Arial, Helvetica, sans-serif; font-size:14pt; text-align:center}
    #button {position:absolute; left:200px; top:200px}
    </STYLE>
    <SCRIPT SRC="button_move.js"></SCRIPT>
    </HEAD>
    <BODY>
    <DIV ID=text>Click the button!</DIV>
    <FORM NAME=EXAMPLE>
    <SPAN ID=button>
    <BUTTON TYPE=BUTTON onMouseOver="moveButton();" onClick="congrats();">Click me!</BUTTON>
    </SPAN>
    </FORM>
    </BODY>
    </HTML>
    =================================
    button_move.js
    -------------------------------------------
    var mouseOverYet=false;

    function moveButton() {
    if(!(mouseOverYet)) {
    taunt();
    mouseOverYet = true;
    }
    var x = Math.random() * 620;
    var y = Math.random() * 400;
    x = Math.floor(x);
    y = Math.floor(y);
    button.style.pixelLeft = x;
    button.style.pixelTop = y;
    }

    function taunt() {
    text.innerText="HAHA!!";
    text.style.fontSize=24px;
    }

    function congrats() {
    text.innerText='Wow! You actually clicked it? Congrats!';
    }
    =================================

    When I put alerts into either event handler, they appear. However, when I put an alert in the moveButton() function, it doesn't appear.
    Any help would be greatly appreciated
    --Xanthos Deia
    ======================
    Do not meedle in the affairs of dragons, for you are crunchy and taste good with ketchup.

  2. #2
    SitePoint Member
    Join Date
    Jun 2001
    Location
    New Jersey
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I may be missing what your question really is because I trid that code and put an alert in the moveButton() function and it appeared as I thought it would. It all seems to work fine
    Why dont I knokw everything yet? its been so long.


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
  •