Unix Hosting News & Commentary

A few important reminders about good coding practices when JavaScript is required for link or forms. Using JavaScript incorrectly can prevent users from right-clicking (or middle-clicking) links to open pages in new windows or tabs if they want, and increases the risk that a critical hyperlink may not function. It may also not work as well down the road if a user someday wants to view the page on their mobile phone, etc.

JavaScript should basically never appear in an href. That is, you should basically never see some JS code here>

The href should almost always include the server-side URL to open, not # or JS code

If JavaScript is required, it should appear as an OnClick event, not in the href. Example:

View Webcast

If you’re interested, more examples can be seen at

In forms, don’t override the standard form Submit button action with JS. Instead, use the onsubmit event handler of the

tag (or the onclick event handler of a non-graphical submit button to call a function that returns a boolean of true or false). Example:

More info:

Speaking of forms: Within forms, instead of showing errors in alert windows, or using non-helpful generic error messages at the top of the page, you can highlight the fields with errors (example: or even hide the valid fields with an option to show them again (example:

If you’re looking for information on designing effective forms, you can find some at

If JavaScript isn’t required or doesn’t add anything, don’t use it

When time allows, please go back to fix incorrect JS use in existing code

  1. No user reviews yet.


Leave a Reply





Blogroll