/    Sign up×
Community /Pin to ProfileBookmark

Variable in link

Hi

I was wondering if someone can help me? How can I pass a variable through a URL?
I want to add the variable in the middle of a URL in the href tag.

For example:
<li><a href”images/file”+ variable +’.jpg”/></a></li>

How is this done using JavaScript?
I have created the variable but how do I add it to the href tag?

Many thanks

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@pc_macauthorApr 18.2013 — Also forgot to add there's multiple links.
Copy linkTweet thisAlerts:
@rajivkumar925Apr 19.2013 — /* jquery */

var variable =myimg;

$("ul").append('<li><a href="images/file' + variable + ' ">' + variable + '</a></li>');
Copy linkTweet thisAlerts:
@rajivkumar925Apr 19.2013 — for multiple links

try

for loop

by index

$("ul").append('<li><a href="images/file' + variable[i] + ' ">' + variable[i] + '</a></li>');
Copy linkTweet thisAlerts:
@pc_macauthorApr 19.2013 — Hi Rajivkumar925 many thanks for replying.

When I append the <li> script to the ul, another script of mine stops working.

I was wondering if you can help me further?

What I am trying to do is show the relevant image depending on what was clicked. (hence having a variable in the url)

Is there a way where I can read what is in div "Box" and then show the relevant <ul id="menu"></ul>.

So if the text in div "Box" = menu1 then <ul id="menu1"></ul> will display OR if div "Box" = menu2 then <ul id="menu2"></ul> will display (and hide menu1)

The text in div "Box" will change when a user clicks an image.

Hope this makes sense. Hope you can help!

I thought having a variable in the url would be the best way but I couldn't get it to work; the value in div "Box" was the variable in the url.

Looking forward to hearing from you.
×

Success!

Help @pc_mac 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.16,
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,
)...