/    Sign up×
Community /Pin to ProfileBookmark

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(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>
[/CODE]

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!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@apeaceMar 11.2008 — Could you post a link?

It's hard to tell what is going on without all the information on the table.
Copy linkTweet thisAlerts:
@KorMar 11.2008 — What is mySecondVar?... Show us the HTML part of the code as well.
×

Success!

Help @ktsirig spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...