Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1]   Go Down

Author Topic: How to reload into innerHTML with Javascript?  (Read 26684 times)

0 Members and 1 Guest are viewing this topic.

ericr23

  • Coppermine newbie
  • Offline Offline
  • Posts: 16
How to reload into innerHTML with Javascript?
« 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:

Code: [Select]
<?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:

Code: [Select]
<?php 
$objCpm
->cpm_viewRandomMedia(5,1);
?>

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

continued ...
Logged

ericr23

  • Coppermine newbie
  • Offline Offline
  • Posts: 16
Re: How to reload into innerHTML with Javascript?
« Reply #1 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:

Code: [Select]
<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.
Logged

ericr23

  • Coppermine newbie
  • Offline Offline
  • Posts: 16
Logged
Pages: [1]   Go Up
 

Page created in 0.016 seconds with 19 queries.