ASP.NET

Moderators: None (Apply to moderate this forum)
Number of threads: 1737
Number of posts: 3308

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help on button.click Posted by Axxaaa on 15 Nov 2011 at 6:23 PM
I'm trying to make it on my website so that if I click a button or image button , another div will load that image. What is the best way to do this?
Report
Re: Help on button.click Posted by Josh Code on 15 Nov 2011 at 7:12 PM
Try the following code snippet. This solution should work independent of popular libraries like jquery.

Copy and paste this code into the HTML of a page and see if it does what you want.

Change the image_url value to whatever image you have. You can give it an absolute or relative path.

<script language="javascript" type="text/javascript">
var image_url="myimage.png";

function loadImageInDiv()
{
 // get reference to the div element that will contain the image
 var div = document.getElementById("imageDisplay");

  // remove children, if there are any.
  while (div.firstChild)
      div.removeChild(div.firstChild);

  var img = document.createElement("img");
   img.src=image_url;

   // add the image to the div so it becomes visible in the page.
  div.appendChild(img);
}

</script>
<!-- The div element that will display the image -->
<div id="imageDisplay">
</div>

<!-- the button to be clicked -->
<input type="button" value="Click Me" onclick="loadImageInDiv()" />



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.