Page 1 of 1

Dynamically swap images based on user interaction

PostPosted: Fri Jan 24, 2014 12:21 pm
by Clifton
Task:
  • Dynamically replace one image on a page with another one.
Procedure:
  1. Draw a field on the page that is sized for the images you want to display. Let's name it "My Pics"
  2. Type the following text in the field "My Pics":
    <img src="../images/%1" style="width:100%; height:100%;" />
    Like this:
    Image 2.png
    on load page for field "My Pics"
    Image 2.png (3.37 KiB) Viewed 6012 times
  3. Create global variables called img and tmpHTML
  4. On load page for field "My Pics" . . .
    Populate the global variable img with our boiler plate html tag (text of field "My Pics").
    Image 1.png
    field "My Pics" text
    Image 1.png (2.45 KiB) Viewed 6028 times
    NOTE: the not (not) img = false condition evaluates whether the global variable has already been set. The expression will evaluate to true if img has already been set.
  5. Copy all of the images you want to switch between into a folder called images and put the folder in the same folder as your tbk. Then flag that folder for inclusion in your export.
    Image 3.png
    Add folders to DHTML export tree with images
    Image 3.png (81.25 KiB) Viewed 6028 times
  6. Draw a list box and type in a list of valid image names.
    Something like this:
    Image 4.png
    Select List Box
    Image 4.png (1.42 KiB) Viewed 6028 times
  7. Create these actions for On select for the list box:
    Image 5.png
    List Box on select
    Image 5.png (2.91 KiB) Viewed 6028 times
    Where pgReplace() parameters look like this:
    Image 6.png
    pgReplace() parameters
    Image 6.png (21.35 KiB) Viewed 6028 times
    AND setHTMLContent() parameters look like this:
    Image 7.png
    setHTMLContent() parameters
    Image 7.png (20.97 KiB) Viewed 6028 times
  8. Export the page; clicking on a image in the list box should dynamically change the image displayed in the field.

Re: Dynamically swap images based on user interaction

PostPosted: Sat Jan 25, 2014 7:52 pm
by PetrH
This worked great. Keeps my page size down so it loads quickly.

I think you might be missing a close-quote in step 2.

I've added a couple of fadeObject() function calls to my implimentation to dress up the presentation of each new image. I need to work up a way to fade the field before loading the next image so that I have a nice fade out, then fade in, presentation.

Re: Dynamically swap images based on user interaction

PostPosted: Sun Jan 26, 2014 11:58 am
by PetrH
This worked great. Keeps my page much smaller than if I had to load all images on the base page.

Re: Dynamically swap images based on user interaction

PostPosted: Sun Jan 26, 2014 12:31 pm
by Clifton
Thanks Peter regarding the note on the typo in step 2. I updated the pic and included another little detail that it is good to know when entering HTML code into fields. You can use comment tags to remind yourself of what the code does as shown in the updated pic for step 2.