PDA

View Full Version : Dynamic Image Selector (dynamic3)



tgavin
01-03-2006, 09:26 PM
I've placed the script into a php function and have it working in multiple instances in one page. Everything is okay except for one thing: if I try to change the text "dynamic3" into a string, it doesn't work anymore.

For instance, if I change the text "dynamic3" to "foo", it works. but if I change it to foo"."$bar it doesn't. Although, every other piece of text I've converted to strings works just fine.

Any ideas?

jscheuer1
01-04-2006, 08:55 AM
foo+"."+$bar

tgavin
01-04-2006, 01:41 PM
foo+"."+$bar
Thanks for your reply. Unfortunately, that didn't work either. It just echoed out the plus signs.

This makes no sense. Echoing "dynamic3"."$name (instead of foo"."$bar) works properly - it always has. It's just that the script refuses to work like this.
<?php
echo "
<form name=\"$name"."dynamicselector\">
<table style=\"width:100%;\">
<tr>
<td align=\"left\" width=\"180\">Please choose the $name image:</td>
<td align=\"left\">
<select name=\"$name"."dynamicselector2\" size=\"1\" class=\"select\" onchange=\"generateimage(this.options[this.selectedIndex].value)\">\n
<option value=\"../../images/template/spacer.gif\" selected>Select a picture</option>\n";
while($pic = readdir($dir)) {
$picpaths[] = $currentdir."/".$pic;
}
sort($picpaths);
foreach($picpaths as $picpath) {
if(!is_dir($picpath)) {
echo '<option value="'.basename($picpath).'">'.basename($picpath).'</option>\n';
}
}
echo" </select>
</td>
</tr>
<tr>
<td colspan=\"2\" align=\"left\"><ilayer id=\"$name"."dynamic1\" width=\"100%\" height=\"115\"><layer id=\"$name"."dynamic2\" width=\"100%\" height=\"115\"><div id=\"dynamic3"."$name\"></div></layer></ilayer></td>
</tr>
</table>
</form>

<script>
var ie4=document.all
var ns6=document.getElementById
var tempobj=document.$name"."dynamicselector.$name"."dynamicselector2
if (ie4||ns6)
var contentobj=document.getElementById? document.getElementById(\"dynamic3"."$name\"): document.all.dynamic3"."$name
function generateimage(which){
if (ie4||ns6){
contentobj.innerHTML='Loading image...'
contentobj.innerHTML='<img src=\"$siteURL"."$directory/'+which+'\" border=\"0\">'
}
else if (document.layers){
document.$name"."dynamic1.document.$name"."dynamic2.document.write('<img src=\"$siteURL"."$directory/'+which+'\" border=\"0\">')
document.$name"."dynamic1.document.$name"."dynamic2.document.close()
}
else
alert('You need NS 4+ or IE 4+ to view the images!')
}

function generatedefault(){
generateimage(tempobj.options[tempobj.options.selectedIndex].value)
}

if (ie4||ns6||document.layers){
if (tempobj.options.selectedIndex!=-1){
if (ns6)
generatedefault()
else
window.onload=generatedefault
}
}
</script>";
?>