Hallo all,
how can I show the output of a php script inside a specific <td> when clicked on the link?
example:

<html>  
<head> <title></title> </head>
<body>
<a onClick="myscript()" href="test.php?a=1&b=345">click here</a>
<table>
<tr>
<td>&nbsp;</td>
<td id="test"></td> </tr>
</table>
</body>
</html>

When the link is clicked, the output of test.php should be displayed
inside the <td> with the id="test".

Is it possible?
Thank in advance
babil

    ok, heres the script code and it works..partialy

    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(); } }

    okay the prob... if I use this string '<?php include (" ' + text + ' ");?>'; I get an error
    Error: unterminated string literal
    Source File: http://localhost/testt/t.php
    Line: 11, Column: 14
    Source Code:
    x.innerHTML = '<br />

    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.

    than you
    cheers

      7 days later

      You are mixing up clientside and serverside code. For these kind of thing you could use AJAX.

      There are several AJAX toolkits out there. I have used SACK succesfully in several projects.

      AJAX is quite easy and powerful once you get the hang of it.

        I havent used SACK but I can warmly recommend XAJAX. Its very easy to use. Heres a page that does similar that you want:

        <?php
        require_once('ajax/xajax.inc.php');
        $xajax = new xajax();
        $xajax->registerFunction("writit");
        $xajax->processRequests();
        
        function
        writit($file) {
        	$objResponse = new xajaxResponse();
        	if (!empty($file)  && file_exists($file))
        		$content = file_get_contents($file);
        	else
        		return $objResponse;
        
        $objResponse->addAssign("test","innerHTML",$content);
        return $objResponse;
        }
        ?>
        <html>
        <head>
        <title>Testisivu</title>
        <?php $xajax->printJavascript('ajax/'); ?>
        </head>
        <body>  
        <a onClick="xajax_writit('test.php'); return false;" href="#">click here</a>
        <table>
        <tr>
        <td>&nbsp;</td>
        <td id="test"></td> </tr>
        </table>
        </body>
        </html>

        Just unpack the latest xajax to folder you want and off you go(almost) 😉

          Write a Reply...