/    Sign up×
Community /Pin to ProfileBookmark

onclick with usemap problem

Hi

I am making a picture gallery in javascript php and mysql.Its running great when using separate image as input type.But when I am mapping a single image into 2 then the picture gallery is not working…Lets show you the code.

[CODE]<table width=”33%” border=”0″>
<?
$show=”none”;
$sql=mysql_query(“SELECT * FROM project_pic where pid=’1′”);
if(mysql_num_rows($sql)>0)
{
$i=1; if($i==1) $show=””;
global $count;
$count=mysql_num_rows($sql);
while($row=mysql_fetch_array($sql))
{
?>
<tr>
<td id=”tdid1<?=$i?>” style=”display:<?=$show?>” align=”center” width=”33%” height=”30%”><img src=”../proj_pics/<?=$row[filename]?>” width=”100″ height=”100″ border=”0″></td>
</tr>
<tr>
<td id=”tdid2<?=$i?>” style=”display:<?=$show?>” align=”center” width=”33%” height=”10%”>
Picture #
<?=$i?>
&nbsp;
<?=$row[title]?>
<input type=”image” name=”prev<?=$i?>” onClick=”prev(<?=$i?>)” src=”some1.gif”>
<input type=”image” name=”next<?=$i?>” onClick=”next(<?=$i?>)” src=”some2.gif”> </td>
<?
$i++;
$show=”none”;
echo “</tr>”;
}
}
?>
</table>[/CODE]

and the javascript function

[CODE]<script language=”javascript”>
var c=<?=$count?>;
function next(i)
{

if(i<c)
{
eval(“tdid1″+i+”.style.display=’none'”);
eval(“tdid2″+i+”.style.display=’none'”);
//eval(“tdid3″+i+”.style.display=’none'”);
var n=i+1;
eval(“tdid1″+n+”.style.display=””);
eval(“tdid2″+n+”.style.display=””);
//eval(“tdid3″+n+”.style.display=””);
}
}
function prev(i)
{
if(i>1)
{
eval(“tdid1″+i+”.style.display=’none'”);
eval(“tdid2″+i+”.style.display=’none'”);
//eval(“tdid3″+i+”.style.display=’none'”);
var n=i-1;
eval(“tdid1″+n+”.style.display=””);
eval(“tdid2″+n+”.style.display=””);
//eval(“tdid3″+n+”.style.display=””);
}
}
</script>[/CODE]

The above is working great but when I am using usemap then not…

[CODE]<table width=”33%” border=”0″>
<?
$show=”none”;
$sql=mysql_query(“SELECT * FROM project_pic where pid=’1′”);
if(mysql_num_rows($sql)>0)
{
$i=1; if($i==1) $show=””;
global $count;
$count=mysql_num_rows($sql);
while($row=mysql_fetch_array($sql))
{
?>
<tr>
<td id=”tdid1<?=$i?>” style=”display:<?=$show?>” align=”center” width=”33%” height=”30%”><img src=”../proj_pics/<?=$row[filename]?>” width=”100″ height=”100″ border=”0″></td>
</tr>
<tr>
<td id=”tdid2<?=$i?>” style=”display:<?=$show?>” align=”center” width=”33%” height=”10%”>
Picture #
<?=$i?>
&nbsp;
<?=$row[title]?>
<img src=”playerbuttons.gif” width=”69″ height=”32″ border=”0″ usemap=”#Map”><map name=”Map”>
<area shape=”circle” coords=”13,15,11″ name=”prev<?=$i?>” onclick=”prev(<?=$i?>)” input type=”image”>
<area shape=”circle” coords=”45,15,11″ name=”next<?=$i?>” onclick=”next(<?=$i?>)” input type=”image”>
</map>
</td>
<?
$i++;
$show=”none”;
echo “</tr>”;
}
}
?>
</table>[/CODE]

in this usemap case the onclicks are getting the value but after 1st click the 2nd image is coming but then after no images and prev() is not working.Is it impossible to use usemap within a loop and call onclick function staying within that loop.

Any suggestion is highly welcomed.Thanks in advance.

Raj.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisMay 09.2007 — Doesn't the AREA tag require an HREF?&lt;area href="#" ... onclick="prev(...);return false" ...&gt;
Copy linkTweet thisAlerts:
@raj_2006authorMay 09.2007 — let me try with that one
Copy linkTweet thisAlerts:
@raj_2006authorMay 09.2007 — i think there is no need to incluse href within area coz the next and prev function is being called by a onclick....not other page.

what happening is the next function is not getting the value after 1st click.
Copy linkTweet thisAlerts:
@ricpMay 09.2007 — 
[CODE]<script language="javascript">
var c=<?=$count?>;
function next(i)
{

if(i<c)
{
eval("tdid1"+i+".style.display='none'");
eval("tdid2"+i+".style.display='none'");
//eval("tdid3"+i+".style.display='none'");
var n=i+1;
eval("tdid1"+n+".style.display=''");
eval("tdid2"+n+".style.display=''");
//eval("tdid3"+n+".style.display=''");
}
}
function prev(i)
{
if(i>1)
{
eval("tdid1"+i+".style.display='none'");
eval("tdid2"+i+".style.display='none'");
//eval("tdid3"+i+".style.display='none'");
var n=i-1;
eval("tdid1"+n+".style.display=''");
eval("tdid2"+n+".style.display=''");
//eval("tdid3"+n+".style.display=''");
}
}
</script>[/CODE]

[/QUOTE]


:eek:

That has to be some of the worst code I have ever seen. You are effectively opening 8 browser instances with those eval's.

I am off to go an lie down, it's all too traumatic..
Copy linkTweet thisAlerts:
@raj_2006authorMay 09.2007 — actually what i had in mind is just to make the picture gallery working through use of onclick(each time a value will be passed) and style.display.......its is working with input type=button...but not working with usemap....Thats the main problem.

sorry cannot understood "You are effectively opening 8 browser instances with those eval's"...eval is just evaluating the string.
×

Success!

Help @raj_2006 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.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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