/    Sign up×
Community /Pin to ProfileBookmark

Image with hyperlink

Greetings!!

I have been trying this command all through the day and have not got it right..Please advice

[CODE] <div style=”float:left;”>
<script type=”text/javascript”>
document.write(“<a href=”http://www.xyz.com/submit?url=”+document.location.href+”&title=”+document.title+” “> <img border=0 src=”http://somewebsite.com/images/120x20_pi_it.gif’ alt=””> Click </a>”);
</script>
</div>[/CODE]

Here I am building a url dynamically using document.location.href and document.title.

The image url is static.

I keep getting a javascript error when the page loads. Please help.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@FangOct 03.2008 — I would always recommend using double quotes in the html and single quotes for the document.write &lt;div style="float:left;"&gt;
&lt;script type="text/javascript"&gt;
document.write('&lt;a href="http://www.xyz.com/submit?url='+document.location.href+'&amp;amp;title='+document.title+'"&gt; &lt;img border="0" src="http://somewebsite.com/images/120x20_pi_it.gif" alt=""&gt; Click &lt;/a&gt;');
&lt;/script&gt;

Escape in end tag: http://www.w3.org/TR/html4/appendix/notes.html#h-B.3.2.1
Copy linkTweet thisAlerts:
@agarwalraunak1authorOct 03.2008 — Fang you rock!! it worked ?

Was the single quote the only mistake i was doing. Why have you put the </a> as </a>

Thanks buddy.
Copy linkTweet thisAlerts:
@FangOct 03.2008 — More than a single quoted mistake and the ampersand should be an entity.

It helps to write the html as you would normally do, then wrap in a single quoted document.write.

The </a> is explained in the W3C link.
×

Success!

Help @agarwalraunak1 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.19,
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,
)...