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

New to DHTML - Hyperlink Question

Status
Not open for further replies.

mans

Programmer
Mar 18, 2000
136
AU
Hello,

i) Can somebody please display some sample code that will show me how to code a Button (On_Click) so that it changes the default linkage path of a hyperlink
ii) Can Hyperlink controls be made to be visible and invisible based on Button action similar to VB, if so, some sample code will be great

Thank You

[sig][/sig]
 
for number one, if when you do onclick, you can possibly do something like.

onclick="javascript:theanchorname.href='the url you want to point to';"

as for number #2 I am uncertain, I do remeber a page I did, where the anchor was in fact a onclick, that called a function, that changed the same anchor's URL, so that as soon as you let go of the mouse button, it took you to the new URL based on the information you chose in the page. [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
Using CSS in IE4+ you can indeed accomplish this feat.

Code:
<html>
<head>
<style type=&quot;text/css&quot;>
 SPAN.visible{visibility:visible}
 SPAN.invisible{visibility:hidden}
</style>
<script language=&quot;javascript&quot;>
function fnSwitch(){
 if (hyper1.className==&quot;visible&quot;){
  hyper1.className=&quot;invisible&quot;;
  hyper2.className=&quot;visible&quot;;
 }
 else{
  hyper1.className=&quot;visible&quot;;
  hyper2.className=&quot;invisible&quot;;
 }
}
</script>
</head>
<body>
<input type=button value=&quot;Switch&quot; onClick=&quot;fnSwitch()&quot;>
<br>
Example 1-<span id=hyper1 class=&quot;visible&quot;><a href=&quot;javascript:fnSomething()&quot;>Go to here</a></span>
<br>
Example 2-<span id=hyper2 class=&quot;invisible&quot;><a href=&quot;javascript:fnSomething()&quot;>Go to there</a></span>
</body>
</html>

Hope it helps, [sig]<p>Rob<br><a href=mailto:robschultz@yahoo.com>robschultz@yahoo.com</a><br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
"Focus on the solution to the problem,<br>
not the obstacles in the way."<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top