Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Include Variable in HREF

Status
Not open for further replies.

nrastogi

Programmer
Jul 19, 2002
52
US
Hello all,

In an JavaScript function, I am getting some value into a variable called procid.

Down the page, I have this link <a href=&quot;/abc/xyz.htm&quot;>

I would like to pass the value of this variable procid as an parameter in the href...so it would look like

<a href=&quot;/abc/xyz.htm?procid=1234&quot;> where 1234 is the actual value from the function.

Thanks a lot,

NRastogi
 
NRastogi,

This will do what you're after:

Code:
<HTML>
<HEAD>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--

	var procid = '1234';

	function parseHref()
	{
		document.getElementById('myHref').href += '?procid=' + procid;
	}

//-->
</SCRIPT>
</HEAD>
<BODY>
<A HREF=&quot;xyz.html&quot; ID=&quot;myHref&quot; onClick=&quot;parseHref();return (true);&quot;>Hello World!</A>
</BODY>
</HTML>

Hope this helps!

Dan
 
var ArrayHref = new Array();
var ArrayDomain = new Array();
var VarDomain =&quot;&quot;;
var VarHref =&quot;&quot;;
var Http =(&quot;http:\\\\var Google = ArrayDomain[0] =(&quot;Google.com&quot;);
// domains should go first so you know
//where and what you are dealing with..
var imgs = ArrayHref[0] =(&quot;//imghp?hl=en&tab=wi&ie=UTF-8&quot;);
var web = ArrayHref[1] =(&quot;//webhp?hl=en&tab=iw&ie=UTF-8&quot;);
var Htmlstr =(&quot;<a href=&quot;+Http+Google+&quot;>&quot;+&quot;Google Root<\/a><a href=&quot;+Http+Google+imgs+&quot;>&quot;+&quot;Google Images<\/a><a href=&quot;Http+Google.web+&quot;>&quot;+&quot;Google Web Pages<\/a>&quot;)
document.body.insertAdjacentHTML(&quot;beforeEnd&quot;, Htmlstr);

hope this help please post if it does.. thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top