/    Sign up×
Community /Pin to ProfileBookmark

Need help with a script

Can anyone help me resolve a javascript problem?

I have a script which creates a tabbed pane of jpgs from a directory on my server. This works perfectly when used once on a page.

When I use it more than once on the same page – its breaking the display. mousing over one of the 2nd or 3rd instances removes the other instances from display.

Each reference calls on a different directory for its images.

Many thanks for any input.

Below is the associated code.

[B]The Style[/B]

[CODE]<style type=”text/css”>

.az1 {background-image:url(../../images/chart_files/strategies/BgImgs/az1.jpg);
background-repeat:no-repeat;
height:16px;}

.az2 {background-image:url(../../images/chart_files/strategies/BgImgs/az2.jpg);
background-repeat:no-repeat;
height:16px;}

.show
{display: block;}

.hidden
{display: none;}

</style>[/CODE]

[B]The Script[/B]

[CODE]<script type=”text/javascript”>
function swchart(is)
{

divs = document.getElementsByTagName(“div”);
for (i = 0; i < divs.length; i++)
{
div = divs[i];
if (div.className == ‘show’)
{
div.className = ‘hidden’;
divn = div;
}
}
document.getElementById(is).className = “show”;
document.getElementById(“d”+is).className = “az1”;
document.getElementById(“d”+divn.id).className = “az2”;

}

</script>[/CODE]

[B]In the body of my html[/B]

[CODE]<div style=”height:20px;”><!– –></div><div align=”center”>
<table align=”center” cellpadding=”0″ cellspacing=”0″>
<tr height=”18px”>

<?php
$ct=0;
if ($handle = opendir(‘././images/chart_files/strategies/tab_1’)) {
while (false !== ($file = readdir($handle))) {
if ($file != “.” && $file != “..”)

{ $ct = $ct + 1;
if ($ct == 1)
{ echo “<td align=’center’ width=’70px’ style=’color:#FFFFFF’><div align=’center’ class=’az1′ id=’d$file’><a style=’font-family:Arial, Helvetica, sans-serif; font-size:120%; color:#ffffff;’ href=”;}
else
{echo “<td align=’center’ width=’70px’ style=’color:#FFFFFF’><div align=’center’ class=’az2′ id=’d$file’><a style=’font-family:Arial, Helvetica, sans-serif; font-size:120%; color:#ffffff;’ href=”;}
$file2 = substr_replace($file,””,-4);
echo ‘”‘;
echo ‘#’;
echo ‘”‘;
echo ” onMouseOver=”;
echo ‘”‘;
echo “swchart(‘”;
echo “$file'”;
echo “);”;
echo ‘”‘;
echo “>”;
echo “$file2”;
echo “</a></div></td><td width=’3px’></td>”;
}
}
closedir($handle);
}
?>
</tr></table>
</div>
<?php
$ct=0;
if ($handle = opendir(‘././images/chart_files/strategies/tab_1’)) {
while (false !== ($file = readdir($handle))) {

if ($file != “.” && $file != “..”) {
$ct = $ct + 1;
if ($ct == 1)
{ echo “<div class=’show’ align=’center’ id='”;}
else
{echo “<div class=’hidden’ align=’center’ id='”;}

echo “$file'”;
echo “>”;
echo “<img src=’../../images/chart_files/strategies/tab_1/”;
echo “$file”;
echo “‘></div>”;
}
}
closedir($handle);
}
?>
<div style=”height:20px;”><!– –></div><div align=”center”>
<table align=”center” cellpadding=”0″ cellspacing=”0″>
<tr height=”18px”>

<?php
$ct=0;
if ($handle = opendir(‘././images/chart_files/strategies/tab_2’)) {
while (false !== ($file = readdir($handle))) {
if ($file != “.” && $file != “..”)

{ $ct = $ct + 1;
if ($ct == 1)
{ echo “<td align=’center’ width=’70px’ style=’color:#FFFFFF’><div align=’center’ class=’az1′ id=’d$file’><a style=’font-family:Arial, Helvetica, sans-serif; font-size:120%; color:#ffffff;’ href=”;}
else
{echo “<td align=’center’ width=’70px’ style=’color:#FFFFFF’><div align=’center’ class=’az2′ id=’d$file’><a style=’font-family:Arial, Helvetica, sans-serif; font-size:120%; color:#ffffff;’ href=”;}
$file2 = substr_replace($file,””,-4);
echo ‘”‘;
echo ‘#’;
echo ‘”‘;
echo ” onMouseOver=”;
echo ‘”‘;
echo “swchart(‘”;
echo “$file'”;
echo “);”;
echo ‘”‘;
echo “>”;
echo “$file2”;
echo “</a></div></td><td width=’3px’></td>”;
}
}
closedir($handle);
}
?>
</tr></table>
</div>
<?php
$ct=0;
if ($handle = opendir(‘././images/chart_files/strategies/tab_2’)) {
while (false !== ($file = readdir($handle))) {

if ($file != “.” && $file != “..”) {
$ct = $ct + 1;
if ($ct == 1)
{ echo “<div class=’show’ align=’center’ id='”;}
else
{echo “<div class=’hidden’ align=’center’ id='”;}

echo “$file'”;
echo “>”;
echo “<img src=’../../images/chart_files/strategies/tab_2/”;
echo “$file”;
echo “‘></div>”;
}
}
closedir($handle);
}
?>
<div style=”height:20px;”><!– –></div><div align=”center”>
<table align=”center” cellpadding=”0″ cellspacing=”0″>
<tr height=”18px”>

<?php
$ct=0;
if ($handle = opendir(‘././images/chart_files/strategies/tab_3’)) {
while (false !== ($file = readdir($handle))) {
if ($file != “.” && $file != “..”)

{ $ct = $ct + 1;
if ($ct == 1)
{ echo “<td align=’center’ width=’70px’ style=’color:#FFFFFF’><div align=’center’ class=’az1′ id=’d$file’><a style=’font-family:Arial, Helvetica, sans-serif; font-size:120%; color:#ffffff;’ href=”;}
else
{echo “<td align=’center’ width=’70px’ style=’color:#FFFFFF’><div align=’center’ class=’az2′ id=’d$file’><a style=’font-family:Arial, Helvetica, sans-serif; font-size:120%; color:#ffffff;’ href=”;}
$file2 = substr_replace($file,””,-4);
echo ‘”‘;
echo ‘#’;
echo ‘”‘;
echo ” onMouseOver=”;
echo ‘”‘;
echo “swchart(‘”;
echo “$file'”;
echo “);”;
echo ‘”‘;
echo “>”;
echo “$file2”;
echo “</a></div></td><td width=’3px’></td>”;
}
}
closedir($handle);
}
?>
</tr></table>
</div>
<?php
$ct=0;
if ($handle = opendir(‘././images/chart_files/strategies/tab_3’)) {
while (false !== ($file = readdir($handle))) {

if ($file != “.” && $file != “..”) {
$ct = $ct + 1;
if ($ct == 1)
{ echo “<div class=’show’ align=’center’ id='”;}
else
{echo “<div class=’hidden’ align=’center’ id='”;}

echo “$file'”;
echo “>”;
echo “<img src=’../../images/chart_files/strategies/tab_3/”;
echo “$file”;
echo “‘></div>”;
}
}
closedir($handle);
}
?>
<div style=”height:20px;”><!– –></div> [/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Angry_Black_ManAug 08.2007 — having taken only a superficial look at your code, im curious if youre getting javascript errors when you do your "second" use? and if so, what exactly do you get?

also, you are far unlikely to get a response to a javascript question when you post PHP code. i know a bit of php, and even if i wanted to try and test your code, i would fail because your PHP tries to open a directory that doesnt exist on my server to grab files that dont exist on this server.

given the code you provided, no one could begin to answer your javascript woes because they wouldnt get past the processing of your PHP.

solution: provide a page on the web that has the final product where people can reproduce your error. then, if youre fortunate you may get some help, but theres no promises!
Copy linkTweet thisAlerts:
@monki_SFauthorAug 08.2007 — I'm not getting any javascript errors on the page

it can be viewed here

http://www.stonehouseequities.com/index.php?option=com_content&task=view&id=2&Itemid=9

In regard to the php code - i thought having a clearer idea of all the processes would be better than a general statement on the issue I'm having.

essentially all the php does is grab the images from the server.
×

Success!

Help @monki_SF spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...