Hey guys,
I'm having a little bit of trouble here.
I have a variable called Latest1 and it's value is some HTML and PHP code.
I have a function that does document.getElementById().innerHTML = Latest1;
So when that happens, it runs the HTML code but for some reason it doesn't run the PHP code.
Because of Javascripts stupid string weirdness, it won't let me type <? because it then treats that as not a string... Which is so annoying.
So, I had to use escape codes:
<?php = %3C%3Fphp
I replaced all my '<?php' to '%3C%3Fphp' and it doesn't work :(

Please help!
Thanks! :-/

7 Years
Discussion Span
Last Post by mangopearapples

It might be easier to use PHP to write your javascript.

You can also play around with this to see if you can get what you are after:
<script type="text/javascript" src="myscript.php"></script>

Otherwise, AJAX?

Edited by SolidSolutions: n/a


I have a button that does a JavaScript function to change a div's content to some PHP code, that means I can't use PHP to do the JavaScript.

I don't really like AJAX...


Can you run that PHP code on page load and "store" that info into a text box value and make that "hidden". Then on the button click you can get that info?


something like


$someVal = //some code to get if needed
$someCodeToStore = //some code to get whatever needed

echo "<input type='text' value='$someCodeToStore' />"


I see...

But how could I get the info from the text field when I click it?

<button onClick="getInfo()" name="codes" />
function getInfo(){
var code = oForm.element["codes"].value;



give the input an id:

echo "<input type='text' id="storedCode" value='$someCodeToStore' />"

Use javascript to get the code by retrieving the value:

var textBoxCode = document.getElementById('storedCode').value;
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.