Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using javascript variable to display image 1

Status
Not open for further replies.

gina03

MIS
Jul 2, 2003
5
IE
Hey. I have the image source in a variable and i want to use it to display the image. Can someone give me a sample line of code to do this please.
 
Depends on where & how you want to display the image but:
[tt]
<script>
var img_file = 'myimage.gif';
function show_image(){
document.getElementById('img_place_holder').innerHTML = '<img src=&quot;' + img_file + '&quot;>';
document.getElementById('img_place_holder').style.visibility = 'visible';
}

</script>
<!-- This div tag acts as an image placeholder -->
<div id=&quot;img_place_holder&quot; style=&quot;visibility:hidden&quot;></div>
<input type=&quot;button&quot; value=&quot;clicky&quot; onClick=&quot;show_image()&quot;>
 
You can't imagine the amount of time you have saved me.
Changed it round to fit in with your code from yesterday and is working perfectly.
Thanks
 
1)first u create an image tag:-
<img src=&quot;xyz.jpg&quot;>
2)store it in a javascript variable:-
var a=<img src=&quot;xyz.jpg&quot;>
3)u can use this variable to display the image whenever u want:-
document.write(a)

hope this is what u were looking for!all the best!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top