0

enter image description here

I am trying to do something similar to the image above, I am using Wordpress and I will build the HTML output with PHP but I need to load a larger image into the Big image slot when a thumbnail image is clicked.

I found a site pof.com that uses this method below but when I try it I get the error below. Please help?

<script>
function B(strNewImage, caption) {
  document.images['MP'].src = strNewImage;
  document.getElementById("icaption").innerHTML = caption;
}
</script>

<img src="http://default_image.jpg" border="0" id="mp" name="MP">

<a href="javascript: B('image_2.jpg','test')"><img src="thumbnails/image_2.jpg" border="0"></a>
<a href="javascript: B('image_3.jpg','test')"><img src="thumbnails/image_3.jpg" border="0"></a>
<a href="javascript: B('image_4.jpg','test')"><img src="thumbnails/image_4.jpg" border="0"></a>
<a href="javascript: B('image_5.jpg','test')"><img src="thumbnails/image_5.jpg" border="0"></a>

ERROR:

Uncaught ReferenceError: B is not defined
2
  • Can you provide a real page example? I tried your code in jsFiddle and it works. Commented May 6, 2012 at 21:46
  • @SamuelHapak: That is the only page I have right now, but it isn't working for me on Google Chrome or Firefox Commented May 6, 2012 at 21:53

2 Answers 2

2

your code is working, DEMO, it's all about where you defined B function. Or maybe It's not working beacuse of undefined type of script tag.

<script type="text/javascript">
function B(strNewImage, caption) {
  document.images['MP'].src = strNewImage;
  document.getElementById("icaption").innerHTML = caption;
}
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

great thanks, I want to eventually change it to use something like date-image with the path to the image but I wanted to get this working first
1

Try to wrap in

window.onload = function() {
...
}

If you have jQuery:

$(function(){
...
});

Or move the script to the bottom of the page.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.