By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,480 Members | 1,743 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,480 IT Pros & Developers. It's quick & easy.

passing value of javascript var in href

P: 1
What I am trying to do is pass the value of a javascript variable as paramter in the href tag. below.. It seems that it should be possible but i can't see to get the right syntax... Any help would be appreciated.

[HTML]<a href="reports_Info_xl.cfm?term=javascript:thisTerm " target="_blank">Data (Excel Spreadsheet)</a>[/HTML]
Oct 3 '05 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
If thisTerm does not change after page load, just use document.write():
Expand|Select|Wrap|Line Numbers
  1. document.write("<a href=\"reports_Info_xl.cfm?term="+ thisTerm + "target=\"_blank\">Data (Excel Spreadsheet)</a>");
If it does change, then give the anchor an id and change its href property dynamically:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("anchorID").href = "reports_Info_xl.cfm?term=" + thisTerm;
Sep 10 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.