1

I developed a html page with a bit of javascript. I have several tags and after clicking a link one of them is dynamically assigned a background image. This url is stored in a global variable. So far so good.

var picture,thumb

function changeDivs(p)
{
     if (p!='') {
        picture = './images/p'+p+'.jpg'; // global url variable
        thumb = './thumbs/p'+p+'.jpg'; // global url variable
        var pic = "url("+thumb+")";
        document.getElementById("poster").style.backgroundImage = pic;
        }
}

I call the function like this:

<a href="javascript:changeDivs('2')">Link</a>

Now I want to make use of a thumbnailviewer script which needs to be accessed like this:

<a href="javascript: global variable" rel="thumbnail"> <!-- Of course this "javascript: global variable" should be a valid url: the stored 'picture' variable -->
        <div id="poster"> 
        </div>
    </a>

So I have stored the url in variable: picture

How can I access the thumbnailviewer script through <a href> AND use the variable. I don't know if the thumbnail script can be called through a function or how.

Thanks a lot!

18
  • I removed your intro about hoping someone can help you. That's what we're all here for and that's why we're looking at your question, so you're in good hands. Welcome to stackoverflow! :D Commented Dec 5, 2010 at 1:28
  • 1
    where and how exactly are you gett the p in changeDivs(p)? Commented Dec 5, 2010 at 1:32
  • This is how I call the changeDivs function: <a href="javascript:changeDivs('1')"> <img src="thumbs/p1.jpg" width="50px" height="70px" /> </a> Commented Dec 5, 2010 at 1:38
  • so, you have solved your issue? Commented Dec 5, 2010 at 1:42
  • No.. not really. Problem is, it's a bit complicated. I use maybe a dozen links to change the bg-img of a div tag in a function, but need that same info for use in a '<a href>' tag. Thanks for the welcome btw :) Commented Dec 5, 2010 at 1:54

1 Answer 1

1

I think this is what you are attempting to achieve. Here is the jsfiddle.
When an '<a href>' is clicked an image becomes the background of "<div id='poster'>"

I replaced your pic's URL with your existing thumbnail url. Please make sure your picture and thumb variable's URL exist. Also, i set width and height of your poster's div.

To work with thumbnailviewer, try the new jsfiddle link please. FYI, dynamicdrive blocked jsfiddle from accessing the js files. Please try the code on your own project.

Sign up to request clarification or add additional context in comments.

3 Comments

Doesn't work. The thumbnailviewer opens, but no picture. (it NEEDS the href url to open it - which is my variable). But now you know the problem :) Thanks so far
this might be the plugin's issue. i had similar issue with dynamic loading after dom is ready VIA javascript with jQuery's NivoSlider. i am not familiar w/ thumbnailviewer to know if this is true however.
Thanks for trying. Since it is 5 am here now... I'll hit the sack :) Thanks again.

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.