Reputation: 72
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() + "'>");
Upvotes: 0
Views: 1443
Reputation: 100527
"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");
Upvotes: 1
Reputation: 499
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.
Upvotes: 0
Reputation: 6948
$("#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
Upvotes: 0