?
Solved

How to get a javascript value in a href

Posted on 2005-05-16
4
Medium Priority
?
3,840 Views
Last Modified: 2008-03-10
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.
0
Comment
Question by:radha77
  • 2
  • 2
4 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 14015043
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
 

Author Comment

by:radha77
ID: 14015090

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

Thanks.
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 150 total points
ID: 14015098
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
 

Author Comment

by:radha77
ID: 14015158
It works now.  Thank you :-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question