Forum Moderators: open

Message Too Old, No Replies

Running onClick function but not able to add the attribute in the html

         

ntbgl

12:48 am on May 23, 2009 (gmt 0)

10+ Year Member



I have a button on my page that looks like this:

<input id="wpSave" name="wpSave" type="submit" tabindex="5" value="Save page" accesskey="s" title="Save your changes [s]" />

Unfortunatly I can't edit this, but I would like to have javascript run a simple function if the button is clicked.

onClick="javascript: pageTracker._trackPageview('/outgoing/example.com');"

How can I have my script watch that button to run the script if someone clicks on it?

Thanks

ntbgl

3:03 am on May 23, 2009 (gmt 0)

10+ Year Member



I tried this, but it didn't seem to work:

document.getElementById('wpSave').onclick=function(){pageTracker._trackPageview('/outgoing/example.com');};

rocknbil

3:52 pm on May 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unfortunately I can't edit this,

But you have access to the page template that contains it? See if you can attach a behavior onload. Untested, as I don't know the nature of "pageTracker":


<script type="text/javascript">
window.onload=function() { setTracker(); };
function setTracker() {
if (document.getElementById('wpSave')) {
document.getElementById('wpSave').onclick=function() {
pageTracker._trackPageview('/outgoing/example.com');
};
}
}
</script>