0

Here is my problem, I need to create a javascript function that takes 2 variables that the user has chosen, and choose what images to produce in 20 divs based on those variables.

I've been trying to figure this out for several days but have gotten no where.

so vars are: year, quarter

images are named by region and the divs are pre-set. so an image would be "regionone_2005_q1.png"

So what I'm looking for is advice on how to solve this issue. I need the browser not to load the image unless it's been asked for based on the user input. I can't use "hide" because it still loads the image and I can't swap out the image based on the code.

I am having trouble finding any tutorials on using javascript variables within html. The catch for this program is that I HAVE to use server side scripting.

3
  • 1
    Don't provide a value for the src attribute of the images, and they wont load. Then set the src attribute in your function. The browser will then download the image and display it. Commented Dec 22, 2011 at 16:57
  • what have you done so far? Any experience with AJAX? Commented Dec 22, 2011 at 16:58
  • Sorry for the delay, just got back from lunch.I've had very little experience in AJAX to date, but will most likely be using that in later versions. @Usman solved it! Commented Dec 22, 2011 at 19:05

1 Answer 1

1

Live Demo: http://jsfiddle.net/LvsJH/

HTML

<img id="myimage" src="#" />

JavaScript

myimage = document.getElementById('myimage');
//I have added a Google image, use your desired image here
myimage.setAttribute('src','http://www.google.com.bd/images/nav_logo99.png');

Put the JS on certain event or after the DOM is ready.

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

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.