0

Now I need to change the displaying image to image control. Help me?

var imlocation1 = "Bhopal/";
var currentdate1 = 0;
var image_number1 = 0;
function ImageArray1(n) {
 this.length = n;
                   for (var i = 1; i <= n; i++) {
                       this[i] = ' '
                   }
               }
               image1 = new ImageArray1(3)
               image1[0] = '2.jpg'
               image1[1] = '4.jpg'
               image1[2] = '1.jpg'
               var rand1 = 100/ image1.length
               function randomimage1() {
                   currentdate1 = new Date()
                   image_number1 = currentdate1.getSeconds()
                   image_number1 = Math.floor(image_number1 / rand1)
                   return (image1[image_number1])
               }
               document.write("<img src='" + imlocation1 + randomimage1() + "'>");
1
  • Please search for answers first so you can provide sample code in your future questions. Commented Jan 11, 2013 at 7:29

3 Answers 3

1

"Img" element have "src" attribute that points to the image on a server. So you need to find the "img" element, and if found set the src attribute.

Basic search for whole question http://www.bing.com/search?q=I+Load+an+Image+to+an+Image+Control+using+JavaScript&src=IE-SearchBox&FORM=IE8SRC give following link: http://www.javascriptexamples.org/2011/01/18/how-to-dynamically-load-an-image-using-javascript/

Sample from the link above:

 <div id="imageContainer"></div>

var img = document.createElement("img");
img.onload = function(e) {
    var container = document.getElementById("imageContainer");
    container.appendChild(e.target);
}
img.setAttribute("src","images/puppy.jpg");
Sign up to request clarification or add additional context in comments.

1 Comment

it is not what i asked, i need to bind the image from javascript with image control in asp.net
0
$("#YourImageId").attr("src", "ImagePath")

If you use webforms - probably

$("#<%=YourImageServerId.ClientID%>")

If it doesn't help - post some code or some more info to your question

Comments

0

The idea of a control only really exists on the server side. Javascript in this case only runs on the client side, on the browser. Once the server renders the image control, you end up with an IMG tag on the client side. If you tag it with an ID or a CSS class, you can find it with Javascript (or even better a library like JQuery) and load images onto it with that.

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.