View Full Version : Construct URL

12-05-2012, 12:18 AM

I have a more than 1000 URL'S like:


where only the foldername changes in the URL.

Now I need a functionality on my page where there are links which has the name same as the folder name and on clicking it , it automatically replaces the name with the foldername and generates and opens the url for me.

For eg:

Suppose there is link with name : OrderEntry . So on clicking it the following URL should be generated:


and opened in the browser. Any kind of help would be appriciated.

Thanks in advance .



Old Pedant
12-05-2012, 12:44 AM

And so why not simply use

<a href="localhost/OrderEntry/trainer/ ">Order Entry</a>

Presumbably, you are generating these links with some server-side code (PHP/ASP/JSP/etc.). No? So let the server side code do it.

But if you *must* do it in JavaScript, I guess you could do something like this:

<a onclick="this.href='localhost/' + this.innerHTML.replace(/\W/g,"") + '/trainer/'; return true;">
Order Entry

The call to replace there will remove all characters except letters, digits, and underlines from the text between the <a> and </a> tags.