1

How can one change the source of an image object in Dashcode (Javascript) at runtime?

I tried:

var image = document.getElementById("image").object; image.src = "IMG_0230.JPG";

Peter
  • 183
  • 2
  • 12

6 Answers6

3

I got this to work
I made sure that the image was stored in the Images folder of the project

var image = document.getElementById("image");
image.firstElementChild.src = "image source";
1

I'm not sure what the point of .object is, the reference should be enough. Is there an object property?

meder omuraliev
  • 183,342
  • 71
  • 393
  • 434
  • Sorry, perhaps I had to be more specific. I used the Image Element from the Library in Dashcode. The image is loaded if I enter the URL or place of the image into the element inspector. My question is, how I can change the source (the image) on runtime. – Peter Nov 06 '10 at 18:50
  • I got it! After digging into the core part of ImageView I found the function: image.setSrc(); – Peter Nov 06 '10 at 21:02
0

I always use this

var image = document.getElementById("imagetobeset");
image.firstElementChild.src = "imagefile";

Where imagetobeset is the name of the element you want to change and imagefile is the name of the file you want your image source to be set to.

user1930797
  • 11
  • 1
  • 2
0

Simply try this, it will work

document.getElementById("image").src="fineName.jpg";
Shankar Prakash G
  • 1,099
  • 18
  • 34
0

I have an image in a list view and I've set up a value transformer for that image that takes the name of the image file stored in the datasource and prepends a URL path to load the file from the server it resides on.

Is this similar to what you're trying to do? If so, then there is a section on Value Transformers in the DashCode doc. It's one of the few things that is documented! :)

tonyopp
  • 171
  • 6
  • Great, thank you. This would be my next task. I found the image.setSrc() function which helped. But this is more elegant. – Peter Nov 12 '10 at 06:36
0

image.setSrc function is not working for me.

I found another way to solve the problem -

document.getElementById("imageView").innerHTML = '<img id="DC_img" 
    class="apple-hidden" apple-group="image" src="' + url + '">';

The Image Part of Dashcode creates a div block and inside it it creates img tag that contains source as attribute. So, either write the innerHTML for imageView or find the img tag with its ID and use setAttribute() function.

Anshul
  • 234
  • 2
  • 16