www.webdeveloper.com
Results 1 to 3 of 3

Thread: PHP Echoing JS Buttons

  1. #1
    Join Date
    Jun 2011
    Posts
    12

    PHP Echoing JS Buttons

    Hello,

    I assume that there is a pretty easy answer for my question, but I am too new to identify the issue by myself.

    All that I am attempting to do is properly echo out JS buttons in PHP, currently I can get them echoed but they are not functioning properly. They echo based off of the info in my database, but when they show up only the very top button shows the "over and out" images and all of the other buttons only show the first image when you hover over it with a mouse. If this does not make sense let me know and I will post a link.

    PHP Code:

    $button 
    "

    <a href=\"../../userprofile.php?username=
    $username\" 
    onMouseOver=\"setOverImg('1','');\" 
    onMouseOut=\"setOutImg('1','');\" 
    target=\"\">
    <img src=\"buttons/button1up.png\" border=\"0\" id=\"button1\" vspace=\"1\" hspace=\"1\">
    </a>
    "
    ;

    echo 
    "$button"
    [js]

    var buttonFolder = "buttons/";

    upSources = new Array("button1up.png");

    overSources = new Array("button1over.png");

    totalButtons = upSources.length;

    function preload() {
    for ( x=0; x<totalButtons; x++ ) {
    buttonUp = new Image();
    buttonUp.src = buttonFolder + upSources[x];
    buttonOver = new Image();
    buttonOver.src = buttonFolder + overSources[x];
    }
    }


    function setOverImg(But, ID) {
    document.getElementById('button' + But + ID).src = buttonFolder + overSources[But-1];
    }


    function setOutImg(But, ID) {
    document.getElementById('button' + But + ID).src = buttonFolder + upSources[But-1];
    }


    [/js]

    Thanks in adavance!

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428

  3. #3
    Join Date
    Jun 2011
    Posts
    12
    PERFECT! Thanks for the tutorial, solved my problem and I learned something new! Thanks again!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles