A
anush
In a javascript file, I have to pass PHP values to the innerHTML. Can
anybody tell how I could do it.
anybody tell how I could do it.
anush said:In a javascript file, I have to pass PHP values to the innerHTML. Can
anybody tell how I could do it.
innerHTML = "<?php echo $escapedToBeSafeForJSValue; ?>";
innerHTML = "<?php echo $escapedToBeSafeForJSValue; ?>";anush said:In a javascript file, I have to pass PHP values to the innerHTML. Can
anybody tell how I could do it.
[...]
That may be a little ambiguous though - as innerHTML is a property of
DOM element nodes.
Maybe:
html_value1 = "<?php echo $escapedToBeSafeForJSValue; ?>";
. . .
your_element.innerHTML=html_value1;
your_element.innerHTML = said:And of course, make sure you've had PHP escape the value properly (as
implied by David).
Always declare your identifiers:
var html_value1 = ...
There is little reason for another variable here:
your_element.innerHTML = "<?php echo $escapedToBeSafeForJSValue; ?>";
That may be a little ambiguous though - as innerHTML is a property of
DOM element nodes. Maybe:
html_value1 = "<?php echo $escapedToBeSafeForJSValue; ?>";
. . .
your_element.innerHTML=html_value1;
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.