Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Links 1

Status
Not open for further replies.

topcat1a

Programmer
Jan 6, 2005
34
GB
Hello,

I’m trying to create a breadcrumb trail and in doing so I dynamically create links to previous pages. I need to be able to insert JavaScript variables into the link. For example:

I have a variable ‘placeName’ with a value ‘FRANCE’ (The value being deduced after some JavaScript function)

I want to amend ‘placeName’ to the end of a URL e.g.: ‘ + ‘placeName’

This then hopefully will be a valid URL and the user can select it as a back link.

I know that + links the two strings, its trying to get the result of this to be placed within the link tag.

So does anyone know how to add JavaScript variables to the end of a URL, example:

<a href = ‘ + placeName’>‘placeName’</a>

tag.

I have looked all over the net and have found nothing to do this

Help!
 
something like this...
Code:
<script>
function changeurl(){
var placename = 'FRANCE';
document.getElementById('myid').href=document.getElementById('myid').href + placename;
}
</script>

<body onload="changeurl();">
<a href="[URL unfurl="true"]http://www.domain.co.uk/"[/URL] id="myid">a link</a>

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
If your anchor has an ID, e.g.:

Code:
<a id="wibble" href="[URL unfurl="true"]http://www.someserver.com/baseLink/">[/URL]

then you can do this:

Code:
document.getElementById('wibble').href += placename;

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
snap! - lol

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Thanks for the really quick answer I’ll give it a go now
 
Ok that is so useful thanks.

Problem is the URL’s are going to be generated when the page loads so I’m not going to know which URL’s to modify until after I’ve created them. And if I can create them correctly I will not need to then modify them.

For example within the script if a keyword appears in the URL then no others will.

With this information I then extract the word from the end of current URL, then depending on what keyword appeared generate some backlinks.

The idea was then create the URLs.

document.write(" + searchTerm1)

So I need some other method to generate the link tag, and add the word to the end.

I hope this makes sense, I think I am so close to finishing this
 
Why don't you know which ones need modifying, how can you create a link if you don't know what that link is?

also if this is purely to enable them to go back to where they just came from, have you broke the 'back button' ?



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Sorry I’m not making myself clear. It is not just to provide a link to the previous page. An example will help me:

TheParisGuideBook

The idea is that from the information in the above URL I can deduce that they must have navigated to the page along the following route:

Home > Search for P > Paris guide books > The Paris Guide Book

There is no other way (well one or two but I’ve got them covered) for the user to get to this page. So I need to create URL’s for each of the parts in the trail. However if I have the URL:


Then the trail must be:

Home > Search for G > Germany guide books

And I must create links to each part in this trail.

As you will notice that I need four links in the first example and only three in the second. So I do not know how many links I will have until I Need to create them.

Hope this helps.

Sorry for the poor explanations
 
Do you not have any serverside processing that can query a database relating to the querystring and produce the dynamicly required links?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Are you saying take the querystring and use this to pull already stored URL's out of the database?
 
yup, some where you need stored that
= Home > Search for G > Germany guide books

however you could always use the following logic...

home = , that won't change

Search for G if you work this out by the fact the first letter of Germany = G then you can use JS to get the substr of ?search (1st char) and then add the value of ?search.




"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
To dynamically create the URL by adding JavaScript variables:

Var finalString
// Some processing of finalString…
document.write("<a href = ' + finalString + ".co.uk'>" + finalString + "</a>")

Sorry for the confusion, I think I just needed some practice on constructing the URL string. Hope this helps other in similar sticky situations which I was in :)
 
Have a star!, you got there in the end.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top