0

can somebody tell me why this does not work:

<script>
<?
echo 'oaktree.addItem("test1", branch1, "")';
echo 'oaktree.addItem("test2", branch1, "")';
?>
</script>

When i take this out of PHP, it works like expected but when doing echo in does nothing... Thanks.

cweiske
31.4k15 gold badges150 silver badges206 bronze badges
asked Apr 14, 2013 at 9:46

1 Answer 1

3

You're missing ; behind the function:

<script>
<?
echo 'oaktree.addItem("test1", branch1, "");';
echo 'oaktree.addItem("test2", branch1, "");';
?>
</script>

echo does not automatically include a new line. The above would echo as:

oaktree.addItem("test1", branch1, "");oaktree.addItem("test1", branch1, "");

Which is why the ; is mandatory for it to work. You can also include a new line yourself but adding a ; by default is a better approach.

You could have probably spotted this error by looking at the source of the page or opening up the console.

answered Apr 14, 2013 at 9:49
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.