1 Replies - 799 Views - Last Post: 10 March 2008 - 05:06 PM

#1 ktsirig  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 14-September 05

add image src from javascript function

Post icon  Posted 10 March 2008 - 04:15 PM

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!

Is This A Good Question/Topic? 0
  • +

Replies To: add image src from javascript function

#2 ahmad_511  Icon User is offline

  • MSX
  • member icon

Reputation: 131
  • View blog
  • Posts: 722
  • Joined: 28-April 07

Re: add image src from javascript function

Posted 10 March 2008 - 05:06 PM

if the mySecondVar is anid of an image tag
you should type
document.getElementById(mySecondVar).src="css/images/show.gif"


and do the same thing for hide.gif

and of course the folder css and images must be exists and hide.gif / show.gif are in the images folder

Regards
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1