How to reload into innerHTML with Javascript? How to reload into innerHTML with Javascript?
 

News:

CPG Release 1.6.27
change DB IP storage fields to accommodate IPv6 addresses
remove use of E_STRICT (PHP 8.4 deprecated)
update README to reflect new website
align code with new .com CPG website
correct deprecation in captcha

Main Menu

How to reload into innerHTML with Javascript?

Started by ericr23, September 26, 2007, 03:53:56 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ericr23

My goal is to allow refreshing a gallery sample in a section of our site's home page. I can only get it to refresh once, however. Any other solution creates endless nested calls. Here's what I've got on the public page:

<?php include_once("./pix/cpmfetch/cpmfetch.php");
$objCpm "";
$objCpm = new cpm("./pix/cpmfetch/cpmfetch_config.php"); ?>

<div id=galsamp>
<?php include('./gallerysample.php'); ?>
<script language="JavaScript">
function refreshgalsamp() {
document.getElementById('galsamp').innerHTML='<?php include("./gallerysample.php"?>';
}
</script>
<a href="javascript:refreshgalsamp();">Refresh</a></font>
</div>


where gallerysample.php is simply:

<?php 
$objCpm
->cpm_viewRandomMedia(5,1);
?>


The "Refresh" link is inside the <div> because it doesn't work a second time.

continued ...

ericr23

I've been trying another approach with no more success, namely, creating an array of the entire gallery in Javascript. But again, only one refresh is possible. In fact, the refresh doesn't finish processing, so it probably embarkis on some endless looping, although I don't see what. Here is what I've got:

<head>
<script>
var Pic = new Array()

<?php
include "./pix/cpmfetch/cpmfetch.php";

$objCpm = new cpm("./pix/cpmfetch/cpmfetch_config.php");
$objCpm->cpm_setReturnType("resultset");
$data $objCpm->cpm_viewRandomMedia(5050"");

$a 0;
foreach (
$data as $row) {
   
$imagethumb $objCpm->getImageToUse($row['pFilepath'], $row['pFilename'], "thumb_");
   
$imagepage "./pix/displayimage.php?pos=-" $row['pPid'];
   print 
"Pic[" $a "]='<a href=" $imagepage "><img src=./pix/" $imagethumb "></a>'\n";
   
$a $a 1;
}
?>


function pix() {
document.write("<table>");
i=0;
while(i<5) {
document.write("<tr><td>");
document.write(Pic[Math.floor(Math.random()*Pic.length)]);
document.write("</td></tr>");
i++;
}
document.write("</table>");
}
</script>
</head>
<body>
<div id=galsamp>
<script>pix();</script>
</div>
<a href='javascript:document.getElementById("galsamp").innerHTML=pix();'>Refresh</a>
</body>


Actually, it appears that the refresh link is ignoring the innerHTML command and just running pix(), because the refresh link disappears. Plus, the refresh continues to run after displaying new pictures.