tags:

views:

2363

answers:

5

HI ,

<script language="javascript" type="text/javascript">
var scrt_var = 10; 
</script>
< html >
 this is a <a href ="2.html & Key= scrt_var">Link  </a>
</htm>

I just want to sent the javascript variable to link ( url parameter )

NO AJAXs

Thanks , Chellappa

+1  A: 
<script>
   var scrt_var = 10;
   document.getElementById("link").setAttribute("href",scrt_var);
</script>
<a id="link">this is a link</a>
erenon
Kylotan
+2  A: 

If you want it to be dynamic, so that the value of the variable at the time of the click is used, do the following:

<script language="javascript" type="text/javascript">
var scrt_var = 10; 
</script>
<a href="2.html" onclick="location.href=this.href+'?key='+scrt_var;return false;">Link</a>

Of course, that's the quick and dirty solution. You should really have a script that after DOM load adds an onclick handler to all relevant <a> elements.

Blixt
Excellent . This is Works for me !!! . Thanks Bllixt
joe
+1  A: 

Alternatively you could just use a document.write:

...HTML
<script type="text\javascript">
var location = "http://";
document.write('<a href="' + location + '">Link text</a>');
</script>
...the rest
Chet
+1  A: 

put id attribute on anchor element

<a id="link2">

set href attribute on page load event:

var scrt_var = 10;
var strLink = "2.html&Key=" + scrt_var;
document.getElementById("link2").setAttribute("href",strLink);
Andrija
+1  A: 
<html>

<script language="javascript" type="text/javascript">
var scrt_var = 10; 
openPage = function() {
location.href = "2.html?Key="+scrt_var;
}
</script>

 this is a <a href ="javascript:openPage()">Link  </a>
</html>
Daniel Moura
Using the < a href= "javascript : ???? " ? , Shall i acesss Varaiabke ?
joe
What is Varaiabke ?
Daniel Moura
sorry . That is Variable .. Spelling Mistake ..
joe