aebstract Posted February 4, 2008 Share Posted February 4, 2008 Hi, I have a little script that replaces the src of an image when I click a link. This presents a gallery type of deal, click a link and the image shows. Well that image needs to link to another specific image, but I don't know how to get the specific part of the href to change to what it needs to be. Here is what I have: <table align=center> <tr><td> <a onclick=\"return showPic(this)\" href=\"$sheet/main.jpg\" title=\"Main $sheet assembly\">Main $sheet assembly</a> <br /> <a onclick=\"return showPic(this)\" href=\"$sheet/A.jpg\" title=\"Assembly A\">Assembly A</a> </td><td align=\"center\" width=\"375\" height=\"375\"> <a href=\"$sheet/mainL.jpg\" rel=\"lightbox\" title=\"$sheet\"><img id=\"placeholder\" src=\"$sheet/main.jpg\" alt=\"\" border=\"0\" /></a> <br /> Click image to view full size. <p id=\desc\">Main $sheet assembly</p> </td><td> </td></tr> </table> When I click on a link, it changes the src to either main or A, however the href stays as $sheet/mainL.jpg, though if I click the second one that changes it to A, it needs to change the href to $sheet/AL.jpg. Basically needs to just change the letter/word between the / & L. Heres the javascript I have currently: <script type="text/javascript" language="javascript"> function showPic (whichpic) { if (document.getElementById) { document.getElementById('placeholder').src = whichpic.href; return false; } else { return true; } } </script> Thanks! Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted February 4, 2008 Share Posted February 4, 2008 Do it like this: <script language="javascript"> function showPic(whichpic) { document.getElementById('placeholder').src = whichpic } </script> <table width=375 height=375> <td> <a href="javascript:showPic('main.jpg')">Main $sheet assembly</a><br/> <a href="javascript:showPic('A.jpg')">Assembly A</a> </td> <td> <img id="placeholder" src="main.jpg" alt="" border="0" width=25 height=25> </td> </table> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.