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

Disable image link after clicking

Status
Not open for further replies.

ronnie98

Technical User
Aug 5, 2004
36
IT
Hi all,
i've searched this forum before posting but didn't find a "clean" solution to my problem.
I have an image with a link on it:
Code:
<a href="#null" onClick="addValue('bold');"><img src="images/myimage.gif" title="Some text" alt="Some text" /></a>
which adds the value in a textarea in the same page via this function:
Code:
function addValue( val ) {

    var tb = document.forms['valuesform'].elements['valuesfield'];

    if ( tb.value.length > 0 ) tb.value += " , ";

    tb.value += val;
}
I need to disable the link after the image has been clicked,preventing multiple insertions of the same value.
I've modified the link this way:
Code:
<a href="#null" onClick="addValue('bold'); this.onclick=null;" ><img ......
but while only one click is allowed,i get many JS errors in the JSConsole like
Code:
uncaught exception etc....
and i think this is not a good sign.
Is there a way to get the same result in a cleaner way?
Thanks in advance.
 
[tt]><a href="#null" onClick="addValue('bold');"><img src="images/myimage.gif" title="Some text" alt="Some text" /></a>
><a href="#null" onClick="addValue('bold'); this.onclick=null;" ><img ......[/tt]

One way is this.
[tt]
<a href="javascript:void(0)" onClick="addValue('bold');[blue]window.addValue=function(){return;};[/blue]"><img src="images/myimage.gif" title="Some text" alt="Some text" /></a>
[/tt]
 
Thank you tsuj,
but the code you provided doesn't seem to work properly.
I have many other images/links within the same page and it actually allows only one value to be inserted into the textarea blocking all the other links after the first click.
BTW,"uncaught exception" errors are shown in JSConsole
 
>BTW,"uncaught exception" errors are shown in JSConsole
I cannot reproduce, but maybe due to other factors.

>I have many other images/links within the same page and it actually allows only one value to be inserted into the textarea blocking all the other links after the first click.
To block only locally, your original may be closer. But the construction can be the same.
[tt]
<a href="javascript:void(0)" onClick="addValue('bold');[blue]this.onclick=function(){return;};[/blue]"><img src="images/myimage.gif" title="Some text" alt="Some text" /></a>
[/tt]
I think there can be other constructions doing similar thing. Try this construction see if it works.

 
Thank you again,now it works as i was expecting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top