Forum Moderators: open
<html>
<head><title></title>
</head>
<body>
<a onClick="myscript()" href="test.php?a=1&b=345">click here</a>
<table>
<tr>
<td> </td>
<td id="test"></td>
</tr>
</table>
</body>
</html>
Is it possible?
Thank in advance
babil
function writit(text) {
if (document.getElementById) {
x = document.getElementById('test');
x.innerHTML = '';
x.innerHTML = '<?php include ("' + text + '");?>';
}
else if (document.all) {
x = document.all['text'];
x.innerHTML = text;
} else if (document.layers) {
x = document.layers['test'];
var text2 = "<?php include ('tst.php');?>";
x.document.open();
x.document.write(text2);
x.document.close();
}
}
if I use this string '<?php include ("tst.php");?>'; everything works fine.
It seems like there is something wrong with the way the string is sewed together.
Anyone an idea? this thing drives me crazy.
thank you
cheers
1) Write your PHP output into a string variable in advance, and populate your innerHTML with an onclick event. A good method, provided your PHP output isn't huge, and doesn't change based on user interaction (an expanding/collapsing menu is a good example)
2) have your onclick trigger an HttpXmlRequest routine, which executes the PHP and inserts the result into the DOM. This method is commonly known as AJAX. There are now so many tutorials online for this it would be silly to repeat it here...
Of the former type there are a few ways to get PHP output into a javascript. MisYu's idea is elegant since it will load separately from the page referencing it.
<script language="javascript" src="mydynamicallygeneratedscript.php" />