0

Here is my Javascript at the top in the head.

<script type="text/javascript" charset="utf-8">
    var myGallery=new Array();
            myGallery[0]="../images/gallery2/2009_09_04-BretErnst_0013.jpg"; 
</script>

Now I want to be able to call myGallery[0] and use that as a href.

So I try:

<li>
    <a href="myGallery[0]" rel="prettyPhoto[gallery1]" title="You can add caption to pictures. You can add caption to pictures. You can add caption to pictures.">
        <img src="myGallery[0]" width="60" height="60" alt="Red round shape" />
    </a>
</li>

But the variable is not being replaced with the string...

Help?

4
  • You have to do document.getElementById('myGallery[0]').href = myGallery[0]; Commented Aug 13, 2012 at 16:55
  • The HTML is already rendered before you are able to do anything with javascript. Hence you are just adding some string to HTML. Commented Aug 13, 2012 at 16:55
  • 2
    Well, you could learn how javascript and html interact by googling some tutorials. You cannot do it the way you are trying to do it because this isn't a serverside language like PHP. Commented Aug 13, 2012 at 16:55
  • I ended up just doing it in .NET Commented Aug 13, 2012 at 21:51

2 Answers 2

2

how about <a href="" onclick="location.href=myGallery[0];return false;">image</a>

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

Comments

1

You can create a function to get the value like

function loadPic(index){
  window.location = myGallery[index];
}

And call the function from the link.

onclick = "loadPic(0)"

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.