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

Easy way to change a change an active link? 1

Status
Not open for further replies.

AndyB21

Programmer
Dec 4, 2000
26
GB
I need to make an active link that will become disabled after it has been clicked for the first time ( or possibly links to a different location ). Has anybody done this with DHTML? I am guessing that you can change the <A Href's properties after an onClick() event..?

Cheers,

Andy..
 
Yep, you can change the href of a link, and yes you can disable the link then by changing the href to:

href=&quot;javascript:void(0)&quot;

which does nothing, and is better than &quot;#&quot; because it doe not make the page jump up to the top.

So all you do is reference the link by giving it an ID:

<a href=&quot;somePage.html&quot; ID=&quot;myLink&quot;>

then you can access it from:

document.all['myLink']


Then just access href in the usual way:


onClick=&quot;document.all['myLink'].href='newHref.htm'&quot;


where new href may be javascript:void(0) for nothing to happen. I think this is the most straight forward way to do this. As I recall perhaps using the document.all array isthe only way to access links, apart from links array.

hope this helps! BEN.
 
This may be so, but when the page is refreshed, the link will be active again!!!

I think this can only be done (after you do the stuff above) by using cookies / ... to set the link on load of the page, to prevent refreshing the page from resetting the link.

Simon
 
Thanks for all the help, this has been my solution! The problem that I had was that when the button was
pressed the first time, it starts off a server-side process and also re-directs to a certain page
dependant on what the outcome on the server is.

Any subsequent quick 'impatient-user' clicks are causing problems on the server, but setting the href to a
void(0) on the onClick() stops the redirection happening even though it is in mid-flow.. So my code ended
up as follows and was called from the onClick=&quot;buttonPressed();&quot; of the offending <A HREF>.

Am I right in thinking that this problem would not have occured if I was using Netscape because it
requires an action to finish before you can click on another link? This seems to be the case as the
application works and the code below is IE specific.

Thanks for all the help..

Andy..

<SCRIPT language = &quot;JavaScript&quot;>

var pressNumber = 0;

function buttonPressed()
{

/*
This function is here to stop multiple clicks of the &quot;submit&quot; button leading
to multiple server requests..
*/

if (pressNumber >= 1)
{
document.all['confirmLink'].href='#';
pressNumber = pressNumber + 1;
}

pressNumber = pressNumber + 1;
}

</SCRIPT>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top