Brendon Rother
Brendon Rother

Reputation: 119

innerHTML in external PHP file

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

Upvotes: 0

Views: 168

Answers (2)

Akilan
Akilan

Reputation: 1717

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.

Upvotes: 1

Jobayer
Jobayer

Reputation: 1231

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.

Upvotes: 0

Related Questions