Forum Moderators: open

Message Too Old, No Replies

Images and Arrays

         

gazza25

2:12 am on Mar 22, 2011 (gmt 0)

10+ Year Member



Hey All,

I have code at present which allows me to select images on a webpage.

<img name="img5">
<img name="img4">
<img name="img3">
<script>
document.images['img5'].src = "5.jpg"
document.images['img4'].src = "4.jpg"
document.images['img3'].src = "3.jpg"

I have a simple HTML form which has checkboxes next to images. What I want to do is select one or more images press submit and on the next screen show the images which had checkboxes selected.

I can pass the values of the images across to the page via post but how would I declare the id into img name as the above example is hard coded?

Thanks

Gary

rainborick

2:39 am on Mar 22, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'd suggest adding an 'id' attribute to your <img> tags so that you can more easily alter all of their attributes using getElementByID(). Of course, if your pages absolutely rely on JavaScript, you can have JavaScript on the target page create the desired <img> elements on the target page as it loads because it will have access to the submitted form data.

gazza25

7:36 pm on Mar 22, 2011 (gmt 0)

10+ Year Member



Hey,

Thanks for your reply.

Could you give me an example of code to help as I am struggling to get this working.

Thanks

Gary