add image src from javascript function

This is a discussion on "add image src from javascript function" within the JavaScript Forum section. This forum, and the thread "add image src from javascript function are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Mar 10th, 2008, 22:06
Up'n'Coming Member
Join Date: Sep 2005
Location: athens
Age: 26
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
add image src from javascript function

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:

PHP: Select all

<script type="text/javascript">
function 
HideShow(myVarmySecondVar
          { 
                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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Mar 14th, 2008, 11:38
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 23
Posts: 1,669
Blog Entries: 1
Thanks: 1
Thanked 4 Times in 4 Posts
Re: add image src from javascript function

The code looks fine. The most likely error is that "css/images/show.gif" does not exist.
This is a common mistake developers make when using relative paths.

on /index.htm "css/images/show.gif" points to:
/css/images/show.gif

on /folder/index.htm "css/images/show.gif" points to:
/folder/css/images/show.gif

Double check.
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript show/hide function danny322 JavaScript Forum 1 May 15th, 2008 12:46
Something kooky going on with my layout when I use a Javascript function... jonnymorris Web Page Design 3 Mar 28th, 2008 16:13
Difficulty calling a javascript function? grittyminder JavaScript Forum 4 Jul 21st, 2005 17:48
help with javascript function kinjiro JavaScript Forum 1 Nov 21st, 2003 15:58
calling a javascript function in from VBscript jakyra Classic ASP 2 Sep 22nd, 2003 23:13


All times are GMT. The time now is 03:37.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42