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! :-/

Recommended Answers

All 8 Replies

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?

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?

Uh, how could I store that PHP code into a text box?

something like

<?php

$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" />
<script>
function getInfo(){
var code = oForm.element["codes"].value;
}
</script>

???

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;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.