Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > JavaScript

Reply
 
LinkBack Thread Tools
Old March 10th, 2008, 07:06 PM   #1
WebForumz Member
 

Join Date: Sep 2005
Location: athens
Age: 27
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 ktsirig is on a distinguished road
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:

Code:
<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!
ktsirig is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old March 14th, 2008, 08:38 AM   #2
Most Reputable Member
 
spinal007's Avatar
 

Join Date: Mar 2004
Location: Good Ol'London
Age: 24
Posts: 1,684
Blog Entries: 1
Thanks: 1
Thanked 4 Times in 4 Posts
Rep Altering Power: 0 spinal007 has a spectacular aura about spinal007 has a spectacular aura about
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.
__________________
Diego - Web-Developer & London SEO Expert
jQuery Plugins: Multiple File Upload, Star Rating, FCKEditor | NEW: XML to JSON
spinal007 is offline  
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

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 1 May 15th, 2008 08:46 AM
Something kooky going on with my layout when I use a Javascript function... jonnymorris HTML, XHTML and CSS 3 March 28th, 2008 01:13 PM
Difficulty calling a javascript function? grittyminder JavaScript 4 July 21st, 2005 01:48 PM
help with javascript function kinjiro JavaScript 1 November 21st, 2003 11:58 AM
calling a javascript function in from VBscript jakyra Classic ASP 2 September 22nd, 2003 07:13 PM


Search Engine Optimization by vBSEO 3.2.0 RC8