Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Displaying 2 images after clicking on one icon ( in different places of the screen )

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Displaying 2 images after clicking on one icon ( in different places of the screen )

    I have a code

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Image Change Demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script type="text/javascript">
    function changeIt(objName)
    {
    //The image object accessed through its id we mentioned in the DIV block which is going to be visible currently
    var obj = document.getElementById(objName);

    //An array that hold the IDs of images that we mentioned in their DIV blocks
    var objId = new Array();

    //Storing the image IDs into the array starts here
    objId[0] = "image1";
    objId[1] = "image2";
    objId[2] = "image3";
    objId[3] = "image4";
    objId[4] = "image5";
    //Storing the image IDs into the array ends here

    //A counter variable going to use for iteration
    var i;

    //A variable that can hold all the other object references other than the object which is going to be visible
    var tempObj;

    //The following loop does the display of a single image based on its ID. The image whose ID we passed into this function will be the
    //only image that is displayed rest of the images will be hidden based on their IDs and that part has been handled by the else part
    //of the if statement within this loop.
    for(i=0;i<objId.length;i++)
    {
    if(objName == objId[i])
    {
    obj.style.display = "block";
    }
    else
    {
    tempObj = document.getElementById(objId[i]);
    tempObj.style.display = "none";
    }
    }
    return;
    }
    </script>
    </head>

    <body>
    <div id="image1">
    <img src="1.jpg" border="0" alt="one" />
    </div>

    <div id="image2" style="display:none">
    <img src="2.jpg" border="0" alt="two" />
    </div>

    <div id="image3" style="display:none">
    <img src="3.jpg" border="0" alt="three" />
    </div>

    <div id="image4" style="display:none">
    <img src="4.jpg" border="0" alt="four" />
    </div>

    <div id="image5" style="display:none">
    <img src="5.jpg" border="0" alt="five" />
    </div>
    <br><br>
    <a id="one" href="#" onclick="changeIt('image1');">one</a>
    <a id="two" href="#" onclick="changeIt('image2');">two</a>
    <a id="three" href="#" onclick="changeIt('image3');">three</a>
    <a id="four" href="#" onclick="changeIt('image4');">four</a>
    <a id="five" href="#" onclick="changeIt('image5');">five</a>
    </body>
    </html>

    My problem is that i have an icon and after clicking on it i want it to return two pictures in two different areas on the screen
    ( not one as usual )
    thanks in advance


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Displaying 2 images after clicking on one icon ( in different places of the screen )

    Thread moved to the other programming languages forum.Given you've only posted html and javascript with no references to java, I'm betting this is a javascript question. This is a java forum, and javascript != java.

Similar Threads

  1. Displaying multiple images using servlet or JSP into html table
    By rajeshraj in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: November 1st, 2012, 12:21 PM
  2. Replies: 9
    Last Post: December 31st, 2011, 01:22 AM
  3. [SOLVED] Printwriter class: displaying File contents to screen with included formatting?
    By mwebb in forum File I/O & Other I/O Streams
    Replies: 10
    Last Post: November 25th, 2011, 11:38 AM
  4. dynamic web project run from double-clicking icon
    By softDeveloper in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 9th, 2011, 04:06 PM