coppermine-gallery.com/forum

Support => cpg1.4.x Support => Older/other versions => cpg1.4 cpmFetch by vuud => Topic started by: ericr23 on September 26, 2007, 03:53:56 PM

Title: How to reload into innerHTML with Javascript?
Post by: ericr23 on September 26, 2007, 03:53:56 PM
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 ...
Title: Re: How to reload into innerHTML with Javascript?
Post by: ericr23 on September 26, 2007, 04:28:28 PM
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.
Title: Re: How to reload into innerHTML with Javascript?
Post by: ericr23 on April 14, 2008, 03:01:12 PM
Use AJAX: http://forum.coppermine-gallery.net/index.php?topic=51895