I want to select image depend on click event and that image should be displayed

Last Reply on Dec 09, 2011 05:31 AM By Mudassar

Posted on Dec 09, 2011 04:07 AM

I want to select image depend on click event and that image should be displayed .

I have taken contetntplaceholder and i m adding div tag dynamically.

I want to take one hiddenfield control as well.

and in img tag in that on click event i am calling one function.

And parameter to function are image id and image path.

Results 1 - 5 of 6 12
Posted on Dec 09, 2011 04:21 AM

check this.

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
    <script type="text/javascript">
        $("#images img").live("click", function () {
            if ($("#container img[id='" + $(this).attr("id") + "']").length == 0) {
                var img = $("<img/>").attr("id", $(this).attr("id"));
                img.attr("src", $(this).attr("src"));
                $("#container").append(img);
            } else {
                alert("Already added");
            }
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id = "images">
    <img id = "img1" src = 'http://www.aspforums.net/Avatars/Mudassar.jpg' />
    <img id = "img3" src = 'http://www.aspforums.net/Avatars/VikasSingh.jpg' />
    </div>
    <hr />
    <div id="container">
        
    </div>
    
    </form>
</body>
</html>

Demo


Posted on Dec 09, 2011 04:26 AM

Ok thanks I will try this


Posted on Dec 09, 2011 05:02 AM

Hi Actually code is fine but i want that when i select the image that image must be replaced by previous image present in div tag.

 


Posted on Dec 09, 2011 05:03 AM

And what if no image present in DIV


Posted on Dec 09, 2011 05:25 AM

I again explain you,what i want to do

I have placeholder control into aspx page.

I add 1 div tag into that placeholder from codebehind.ok.

then from database Image table I add image into that div tag..suppose I have 4 images into database table,then 4 images will added into div tag.

now in my aspx page 1 hardcoded image tag is there.

like<image id="imgshow" src=""/>

Now if i run this code,n if i select a particular image which is coming from database,then that particular image want to display into that hardcoded [imgshow] tag..

like imgshow.src="src of selected image from database."