Jump to content

replace part of a href?


aebstract

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/89385-replace-part-of-a-href/
Share on other sites

 

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.