Execute JavaScript/DOM before PHP
Posted: Mon Aug 25, 2008 5:10 am
I have this function:
If I write simple HTML code in myCode div, works perfect, but when I write PHP code, it gets executed, and there's nothing to replace anymore.
If you haven't already figured out, I want to replace the "<" and the ">", so the code is being displayed, not executed.
Any suggestions?
Code: Select all
<head>
<script type="text/javascript">
function change(){
var x = document.getElementById("myCode");
var y = x.innerHTML;
y= y.replace(/</g, "<")
y= y.replace(/>/g,">")
document.getElementById('myCode').innerHTML = y;
}
</script>
</head>
<body onload="change();">
<div id="myCode">
<?php echo 'Batman'; ?>
</div>
</body>
If you haven't already figured out, I want to replace the "<" and the ">", so the code is being displayed, not executed.
Any suggestions?