homepage Welcome to WebmasterWorld Guest from 54.211.201.65
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
add image src from javascript function
ktsirig




msg:3596899
 11:10 pm on Mar 10, 2008 (gmt 0)

Hello,
I have a js function inside the head of a page of mine which takes 2 arguments that are created dynamically based on what I retrieve from a database.
My question is whether I can set the attribute src of the <img> tag through the js function. What I have is:

<script type="text/javascript">
function HideShow(myVar, mySecondVar)
{
if (document.getElementById(myVar).style.display == 'none')
{
document.getElementById(myVar).style.display = 'inline'
-----> mySecondVar.src = "css/images/show.gif"
}
else
{
document.getElementById(myVar).style.display = 'none'
-----> mySecondVar.src = "css/images/hide.gif"
}
}
</script>

The lines with the arrow in front of them do not work, presumably there is a mistake in the syntax because I see no image...

I would greatly appreciate any help!

 

MarkFilipak




msg:3596908
 11:23 pm on Mar 10, 2008 (gmt 0)

> can set the attribute src of the <img> tag through the js function
Yes, and it will cause the image to be immediately fetched!

> lines with the arrow in front of them do not work
try mySecondVar.setAttribute('src', 'css/images/show.gif');

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved