Log in

View Full Version : Echo a part of a javascript



Null
05-06-2006, 03:21 PM
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?

Twey
05-06-2006, 04:04 PM
<?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.

Null
05-06-2006, 04:22 PM
Ok thx