/    Sign up×
Community /Pin to ProfileBookmark

<script> tags inside <img> statement

I’m trying to embed <script> tags inside my <img> tag, but I don’t seem to be writing the information inside the <script> tag. Here is the code…

—->
<script>document.writeln(‘<img src=’ + pic + ‘>’)</script>
—-<

Where I set the variable ‘pic’ in the <head>…

—–>
<script type=”text/javascript”>
var pic = “../images/arrows.gif”;
var pic_value = “closed”;
function picture{
if (pic_value == “open”){
pic = “../image/arrows.gif”;
} else{
pic = “../images/arrows.gif”;
}
}
function populate{

picture;

}
</script>
—–<

The .html just has the <script>~</script> written out and my image doesn’t show up. Any ideas?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@digitalentropyauthorApr 06.2007 — okay, apparently my <script> code is fine. The problem I'm having is with the variable 'pic'.

I'm just doing...

var pic;

pic = "arrows.gif";




Is this the wrong way to define a variable?
Copy linkTweet thisAlerts:
@digitalentropyauthorApr 06.2007 — So, I've gotten this code working.

I had to separate the variable definitions from the functions (i.e. I put the definitions in one <script></script> tag set and the functions in another). Now, I thought local variables were only those defined within a function, but would I be correct in saying that my problem was that variables are considered local if defined within a <script></script> tag set that contains functions also?
×

Success!

Help @digitalentropy 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.6,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...