• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to select an image on a dynamically created tab and display it before submitting using jQuery

 
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am dynamically creating tabs and on each tab I display an image. I then allow a new image to be selected by the user to replace it. When the new image is selected on the first tab it is displayed (the original image displayed is replaced). However, on the subsequent tabs the original image is not replaced (the new image name is displayed). The image selected on subsequent tabs are displayed on the first tab. There is no error in the console.

           

js:

             
 
Glyndwr Bartlett
Ranch Hand
Posts: 176
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer to this is to make each "id=" unique. In this case id="photo" needs to change to "id="'+obj.eventId+'"' and "id="campImage""chages to "id="campImage'+obj.eventId+'"".The eventId is the primary key for the row in the table and is therefore unique.

The code is:
         

So you now ask, if the "id" changes each time how do I recognise it has changed? Well in the class add a unique name, I use "photo-input" and use that. So the JS is:

                     
So, you will notice that I have id set to a unique value for each tab. I then append that value to the input id that I want to populate (picture is not the only one in this form, I have kept this simple).
 
He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic