0

When inserting HTML code with PHP the <script> brackets are not being interpreted though the <p> tag works just fine.

This is the PHP excerpt:

echo "<p>Test</p><script type='text/javascript'>document.getElementById('signalframe1').src = 'http://live.telldus.com/device/switch?mode=on&id=101443';</script>";

Is my syntax wrong or is later inserted JavaScript just not being executed?

Thanks a lot!

5
  • 1
    What does not work? Context? More infos? Commented Sep 12, 2012 at 10:30
  • so what is the actual output, i would expect this to work ..? Commented Sep 12, 2012 at 10:30
  • 1
    Is the signalframe1 element (I'm guessing an <iframe>) defined above in the outputted HTML code? If not, document.getElementById('signalframe1') will return empty. Commented Sep 12, 2012 at 10:33
  • The inserted JavaScript is supposed to change the source of the iframe to the given URL. When looking into the source code in the browser the <div> where the code is supposed to go is empty. The "p" tag though is being interpreted and displayed correctly. Any ideas? Commented Sep 12, 2012 at 10:36
  • Yes, the iframe tag is defined above the outputted code. Commented Sep 12, 2012 at 10:37

1 Answer 1

1

your javascript does not know about the signalframe1 element, because this runtime (later added) javascript only knows about the html added with this php script, for that you can add one copy of the script in the html page so that its present when the html is loaded, and the other in php if you need bcz later if you want to add some html there in the php and that should work on that html doc. hope it will help. Thanks

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

1 Comment

Thanks, you were right! I just inserted a whole new iframe with the URL as source. That did the trick.

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.