View Single Post
Old 03-16-2013, 07:28 AM   PM User | #4
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Never attach JavaScript insiide the href attribute.

Best is to not jumble any of the JavaScript in the HTML at all and put ALL the JavaScript in the external file.

<a id="a1" href="nojs.htm">click here</a>

and in the external HTML

document.getElementById('a1').onclick = function() {..... ; return false;}

the code for your function goes in place of the ..... in the above command that is in the external JavaScript file.

You attach JavaScript in the external file to HTML in the web page using the id of the element you want to attach it to (or in some cases class names if the same code is to be attached to multiple elements

The code suggested by DMN was considered to be bad practice in Netscape 2 and worse practice in every browser since then.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote