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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to change HREF value

Status
Not open for further replies.

budapestnori

Technical User
Jan 15, 2004
33
HU
I want to have a script that when run, can dynamically change the value of a <a> tag's href value. The reason being is I have an asp page for a photography gallery which has an div element in which images are displayed. I have several links on this page which allow the user to change the background of the div element.

It is done like this:

function changeColor(xyz) {
var x;
var z;
x = xyz.currentStyle[ &quot;backgroundColor&quot; ];
z = xyz.currentStyle[ &quot;color&quot; ];
document.getElementById('container').style.backgroundColor = x;
document.getElementById('container').style.color = z;
return;
}

Ok, well on this asp gallery asp page, I also have links which href itself. ie., <a href=&quot;gallery.asp?type=wedding&quot;>
Wedding</a>

But when the background is changed, I want to change the href value to &quot;gallery.asp?type=wedding&bgcolor=#f00&color=#000&quot;

Can this be done?

Thanks so much
 
Damn, this is so frustrating:
This is what I have:

Function:

function changeColor(xyz) {
var x;
var z;
x = xyz.currentStyle[ &quot;backgroundColor&quot; ];
z = xyz.currentStyle[ &quot;color&quot; ];

document.getElementById('container').style.backgroundColor = x;

document.getElementById('container').style.color = z;

document.getElementById('myHref').href += '?procid=' + x;

return;
}

Call to Function:

<a href=&quot;#&quot; class=&quot;seventeen&quot; onClick=&quot;changeColor(this);&quot;>Click</a>


Target HREF to Change:

<a href=&quot;wedding_gallery.asp?category=w&quot; ID=&quot;myHref&quot;>Wedding</a>


BUT THE HREF IN THE TARGET DOES NOT CHANGE!!! AAAAAARGH!
 
It just dawned on me, that changeColor() could be called many times, so I wouldn't want every time it is called for it to be continually appending the value onto the url. Does that make sense?
 
like this?
Code:
function changeColor(xyz) {
	var x = xyz.currentStyle[ &quot;backgroundColor&quot; ];
	var z = xyz.currentStyle[ &quot;color&quot; ];

	document.getElementById('container').style.backgroundColor = x;
	document.getElementById('container').style.color = z;

	var sHref = document.getElementById('myHref').href;
	sHref = sHref.substring(0, sHref.indexOf(&quot;?&quot;));
	sHref += '?procid=' + x;
	document.getElementById('myHref').href = sHref;

	return;
}

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top