wood burning stoves*
The moose likes HTML, CSS and JavaScript and the fly likes calling a Javascript variable in anchor tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "calling a Javascript variable in anchor tag" Watch "calling a Javascript variable in anchor tag" New topic
Author

calling a Javascript variable in anchor tag

sundar sankaran
Greenhorn

Joined: Aug 10, 2004
Posts: 10
I want to know how to call a Javascript variable in html a href tag. Here is my snapshot of my requirement:
<html>
<head>
<script type="text/JavaScript">
var path="/u03/abc/app/Learning/";
</head>
</script>
<body>
<a href=path variable to come here"TC1011018C.html" target="rframe">sometext1 </a> <br>

<a href="TC2062021C.html" target="rframe">sometext2</a> <br>

<a href="TC3043046C.html" target="rframe">sometext3</a> <br>

</body>
</html>
My path variable has to come before href html link(TC1011018C.html). I googled several site. How it can be acheived?? Please help me.

Regards,
Sundar
sundar sankaran
Greenhorn

Joined: Aug 10, 2004
Posts: 10
In addition to the above thread .Here I am using frames(left and right)Here the all the links will be there in left frame. On clicking the link, the correponding html file will be open in right frame.
vijaya bharath
Ranch Hand

Joined: Jun 10, 2005
Posts: 66
Hi,

can't you write the anchor tag in javascript only.If so can you please try this.


Regards,<br />Vijaya Bharath.<br />SCJP1.4 <br />SCWCD5.0
sundar sankaran
Greenhorn

Joined: Aug 10, 2004
Posts: 10
Bharath,
This solution I tried, but is very tedious work. I cannot embed some 50 a href tags to document.write. Please give alternate solution to call the javascript variable in a href.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9930
    
159

How about this:

[ December 19, 2006: Message edited by: Jaikiran Pai ]

[My Blog] [JavaRanch Journal]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
AND can I ask why you are relying on JavaScript tp do this when you have a reliable thing called the serverside language to do it. What if the user clicks on a link before the page loads? Looks like they will get an error in the right frame.

Eric
sundar sankaran
Greenhorn

Joined: Aug 10, 2004
Posts: 10
Jaikiran,
I have tried your thing, but I am getting fullpath like this see the bolded one:
eg:
abc/jsp/openhyperlink.jsp?fileName=/u03/app/Learning/http://localhost:8080/abc/jsp/TC1011018C.html
I must get like this "
abc/jsp/openhyperlink.jsp?fileName=/u03/app/Learning/TC1011018C.html

Please let me know the solution for this.

To answer Eric question, Here my requirement is we need to dump lot of elearning courses in a separate content server. The elearning courses will have many html, swf, img files etc. I calling this html files via server side script ie from Jsp. But I cannot write any Jsp code in the content server folder and call it in Jsp or servlet. Did I answer your question.
sundar sankaran
Greenhorn

Joined: Aug 10, 2004
Posts: 10
Has anyone have solution for this. I am also struck with other code that how to call a variable in img src tag:
eg:
<html>
<head>
<script>
var k="\app\abc\adi\"
</script>

<body>
<img src =how to call the k variable"some.gif">
</body>
</html>
I am totaly struck. It is urgent requirement. Please give a solution.

regards,
Sundar
 
 
subject: calling a Javascript variable in anchor tag
 
Similar Threads
Is there something better then event.pageX/Y?
"a name" tag
Help with displaying data properly
Is there a way to automatically default a webpage to a specific area upon load?
How to create a slide menu in all browsers