Topic: what exactly replaces 'onclick' if this is deprecated

i have a link at the bottom of my page which allows users to print the page. It uses onClick="javascript:window.print();" but this causes the page to fail its validation. Can anyone be so kind to rectify this issue for me - tell  me what i need to do to fix this. Rgds.

Vote up Vote down

Re: what exactly replaces 'onclick' if this is deprecated

Hi, are you using an XHTML Doctype? That seems to be the reason why. I googled for a while but was unable to find an answer other than changing your doctype to HTML.

Vote up Vote down

Re: what exactly replaces 'onclick' if this is deprecated

Ideally, you'd be looking to remove onClick entirely and use unobtrusive techniques, but this should work:

<a  href="#" onclick="window.print()">print</a>

Note that onclick is in lower case and the javascript: part is removed.

Vote up Vote down