0

I have this code:

 document.getElementById('root').style.left = '<?php echo $page_position[$info["os"]][$info["browser"]][0]; ?>';
 document.getElementById('root').style.top = '<?php echo $page_position[$info["os"]][$info["browser"]][1]; ?>';

Why won't this work like this?

Can anybody point me in the right direction?

EDIT:

<?php echo $page_position[$info["os"]][$info["browser"]][1]; ?>

echoed "top:300px;"

Sorry guys, very stupid error of mine :/

5
  • Can you post more of the script? Commented Jan 5, 2011 at 18:32
  • Is the echoing in the code above correct? I think that's the problem... The normal php echo outside the js part works... Commented Jan 5, 2011 at 18:35
  • What do you mean by "won't work?" What are your expected results, what is actually happening, and how are you running it? Commented Jan 5, 2011 at 18:36
  • Have you done a var_dump of your variables to make sure the contents are all correct? Commented Jan 5, 2011 at 18:36
  • The variables echo as usual outside the js tag... :/ Commented Jan 5, 2011 at 18:37

2 Answers 2

3

If you put it in a .js file, it won't work because it must be in a page that is parsed for PHP (.php).

Sign up to request clarification or add additional context in comments.

1 Comment

Please post more of the script.
1

Things to check:

  1. Check to make sure those variables are available. print_r($info) will help you out.
  2. Make sure that the code is actually being filled with those variables (symptom of #1). View source and check that they are there.
  3. Ensure you don't have any JavaScript errors preceding your code. Open your console (like Firebug) and check to make sure you don't.
  4. Ensure that a root element exists. Again, use your console.

My money goes on #3, you probably have a JavaScript error somewhere that is stopping execution of the script.

Comments

Your Answer

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.