How to get a javascript value in a href

Hi,

I have js function that returns a value that contains the path of a document.  I want to pass it in a href link on the same page.  Upon clicking the link, user needs to go that document.  Pls let me know how I can achieve that.

Thanks.
radha77Asked:
Who is Participating?
 
ZvonkoConnect With a Mentor Systems architectCommented:
Sorry, I missread your question.
So you already have a function that returns the string which is the path to some document.
Then your link can be like this:

<a href="#" onClick="this.href=yourFunction()">Document</a>



0
 
ZvonkoSystems architectCommented:
The links are contained in a collection of document links.
So if you want to change some link's href after some script calculation, then you can do it like this:

<script>
function addPath(lnkNum, thePath){
  var lnk = document.links;
  lnk[lnkNum].href += ((lnk[lnkNum].href.indexOf("?")>0)?"&":"?")+"path="+thePath;
}

0
 
radha77Author Commented:

Its not working.  Can you tell me how my a href in my form should look like??  

Thanks.
0
 
radha77Author Commented:
It works now.  Thank you :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.