Here is a way to have a link that doesn't change the browser's location (for when you just want to run some JavaScript) without relying on the href="#" or href="javascript:void(0);" tricks working in the visitor's browser.
It works using a non-parsed header script that simulates the server response "204 No Content" message. This tells the browser that it should leave whatever is currently loaded alone. Click the "Yes" and "No" below to activate their respective radio buttons. If your browser is JavaScript-enabled and it recognizes that return false; in the onClick event handler means that it shouldn't folow the href, then the radio button should activate and your browser shouldn't try to make a call back to the server. However, if you disable JavaScript or if your browser ignores the return false; then you should see your browser make a call back to the server and then do nothing. (If you're using IE5 you'll notice that I've also included accesskeys for the radio buttons denoted by the underlined characters in the text.)
Here's the code for the puny little Perl script, called nph-do_no.cgi, that does all the magic:
#!/usr/bin/perl
print "$ENV{'SERVER_PROTOCOL'} 204 No Content\n";
print "Server: $ENV{'SERVER_SOFTWARE'}\n";
print "Content-type: text/plain\n\n";
exit(0);
The secret to making any old CGI script into a non-parsed header script is naming it with the nph- prefix. The server will then allow the CGI script to generate all its own MIME headers instead of generating them automatically.
For general information on non-parsed header scripts check out these resources: