Forum Moderators: open

Message Too Old, No Replies

Changing "onClick" attribute of link through another link

The format I've been following for changing other attributes doesn't work

         

Jeremy_H

6:27 pm on Jul 19, 2006 (gmt 0)

10+ Year Member



This is seems a little weird, but I'm trying to change the OnClick function on one of my links based on another link.

I would like to change the onclick attribute of this link.

<a href="/109/" onClick="return o('109');" id="sub4">...</a>

With any of these links:

<a href="/208/" onClick="return s(208);">...</a>
<a href="/209/" onClick="return s(209);">...</a>
<a href="/210/" onClick="return s(210);">...</a>

This is what my s function javascript looks like so far:

function s(x){
document.getElementById("sub4").onClick="return o("+x+");";
return false;
}

I've followed the same format I used when changing other attributes of various other elements, but this one doesn't seem to work.

Do I need to do something special with this since I want to change a javascript attribute? Is it impossible?

Any advice is much appreciated.

Thanks

daveVk

5:39 am on Jul 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try

document.getElementById("sub4").onclick="return o("+x+");";

think "onclick" needs to be all lower case

banaax

7:09 pm on Jul 25, 2006 (gmt 0)

10+ Year Member



to work in IE I think you have to do something like this

element.attachEvent('onclick',someFunction);