javascript - passing parameter to url via <a> tag int html - Stack Overflow

I have in a variable (var lan= urlParam('language')) the selected language.I want to pass th

I have in a variable (var lan= urlParam('language')) the selected language. I want to pass this language as parameter (without using PHP) in a url in an "a" tag, like this:

<a href=".aspx?languageCode=lan"> 

but it doesn't work.

I am waiting for your answers. Thank you a lot.

I have in a variable (var lan= urlParam('language')) the selected language. I want to pass this language as parameter (without using PHP) in a url in an "a" tag, like this:

<a href="http://hotelsbined.sitewish.gr/HotelNameSearch.aspx?languageCode=lan"> 

but it doesn't work.

I am waiting for your answers. Thank you a lot.

Share Improve this question edited Sep 14, 2011 at 13:45 Quasdunk 15.2k3 gold badges39 silver badges47 bronze badges asked Sep 14, 2011 at 13:36 AlekaAleka 111 gold badge1 silver badge2 bronze badges 1
  • You want to dynamically, using JavaScript, add a new GET parameter to every link that is on the page. Is that correct? – Jan Hančič Commented Sep 14, 2011 at 13:38
Add a ment  | 

2 Answers 2

Reset to default 2

Your url is inside a string, so it won't put the value of your variable, but just the string "lan".

Give an ID to your link, so you can take it and change its url with javascript.

<a id="foo" href="http://hotelsbined.sitewish.gr/HotelNameSearch.aspx">

Then, with JS

document.getElementById('foo').setAttribute('href', 'http://hotelsbined.sitewish.gr/HotelNameSearch.aspx?languageCode=' + lan);

If I understand correctly, you can just use document.write to print the link and add the variable as the language parameter.

<script type="text/javascript">document.write("<a href=\"http://hotelsbined.sitewish.gr/HotelNameSearch.aspx?languageCode=" + lan + "\">link description</a>");</script>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745453471a4628376.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信