0

I'm trying to change the text within a P tag from an external PHP file. Is there someway I can use innerHTML?

currently this is the line of code I'm trying to use but it doesn't seem to work

echo '<script>document.getElementById("response").innerHTML = "test";</script>';

I tried just doing

document.getElementById("response").innerHTML = "test";

However it also doesn't seem to work, I also tried the echo without the script tags

3
  • by "external PHP file," do you mean a file on a website? Or just one on a server somewhere? Commented Oct 15, 2014 at 9:07
  • So you are including your external PHP file and you would like to change the external loaded content via javascript? Commented Oct 15, 2014 at 9:08
  • Try echo '<script>alert('works!!!');</script>'; Commented Oct 15, 2014 at 9:17

2 Answers 2

1

To use javascript extenal php, u have to check alreadywindow loaded (document.ready function in Jquery).

In your case, you have to use window.load function and give the text text change inside that.

Basically php loaded first than javascript.

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

Comments

0

Using innerHTML, you can change text within a page, if you want to add anything from external php page, you need to use AJAX for loading it.

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.