Results 1 to 3 of 3

Thread: Echo a part of a javascript

  1. #1
    Join Date
    Aug 2005
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Echo a part of a javascript

    Hi,

    I have this variable:
    $name = $user->online[$i]['name'];

    It shows all the users online (excample John, Max and Jack)

    Now I have this part of javascript:
    dd.elements.<?php echo $name; ?>.moveTo(xPos, yPos);

    This gives a error when there are more than 1 user online.

    I need a result like:
    dd.elements.John.moveTo(xPos, yPos);
    dd.elements.Max.moveTo(xPos, yPos);
    dd.elements.Jack.moveTo(xPos, yPos);

    How do I do this?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <?php for($i=0;$i<count($user->online);$i++) { ?>
      document.forms['dd'].elements['<?php echo($user->online[$i]['name']); ?>'].moveTo(xPos, yPos);
    <?php } ?>
    Assuming you've done everything else correctly, that should be essentially what you're already doing.

    P.S. never assume that a form will be globally available and identifiable by a variable of its name or ID.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2005
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok thx

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
  •