My code works how I want to do it, when converted a fixed value from the combo box to the right in the image Image goes Although this is not only the image, I want to change that change. On that image I have that HTML page (logo, widget images, act). I do not want to do this, but only my desired image here is my code:
html:
& lt; Form name = "Animals" & gt; & Lt; Select id = "imagecb" & gt; & Lt; Option value = "Option 1" selected & gt; Please select ... & lt; / Options & gt; & Lt; Option value = "option 2" & gt; Cat & lt; / Options & gt; & Lt; Option value = "option3" & gt; Dogs & lt; / Options & gt; & Lt; Option value = "option4" & gt; Birds & lt; / Options & gt; & Lt; Option value = "option5" & gt; Hamster & lt; / Options & gt; & Lt; / Select & gt; & Lt; Br / & gt; & Lt; / Form & gt; & Lt ;! - This is the desired image to change through the selected option in the selectbox - & gt; & Lt; Img src = "(url) cat.png" />
Javascript:
& lt; Script & gt; JQuery (function ($) {var pictureList = ["(url) cat.png", "(url) dog.png", "(url) bird.png", "(url) hampster.png"]; $ ( '#imagecb'). Change (function () {var index = $ (this) .find (': selected') .index (); $ ('img'). Attr ("src", picture list [index]) ;});}); & Lt; / Script & gt;
If anyone can help, that would be good.
If you can use it $ ('img'). Attr ("src", picture list [index]);
This will replace all the images on your page.
Try adding a class to the image tag that you want to change. Like & lt; Img class = "change_image" .....
Now switch to javascript - $ ('Attr ("src", picture list [index]);
Comments
Post a Comment