Linux technical support, Technical Blogs, Cheap dedicated server support, Cheap linux dedicated server support, Cheap windows dedicated server, Dedicated server support, Data center Operation, System Administration, Bash and perl scripts for server maintainance

Java script tips for integrating with forms and URL

April 10th, 2008 by Billa in Java

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

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 http://www.evolt.org/article/Links_and_JavaScript_Living_Together_in_Harmony/17/20938/

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: http://www.evolt.org/article/Forms_and_JavaScript_Living_Together_in_Harmony/17/28553/index.html

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: http://www.themaninblue.com/writing/perspective/2005/10/05/form/form4.htm) or even hide the valid fields with an option to show them again (example: http://www.themaninblue.com/writing/perspective/2005/10/05/form/form5.htm).

If you’re looking for information on designing effective forms, you can find some at http://www.alistapart.com/articles/sensibleforms

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

Leave a reply

You must be logged in to post a comment.

purchase accutane online buy accutane cialis prescription order cialis without prescription buy cheap soma online generic synthroid accutane pills cheapest generic viagra lowest price acomplia propecia without a prescription cheap cialis from usa tablet viagra certified viagra buy cialis without prescription levitra discount cheap viagra in usa lowest price clomid order cheap viagra acomplia sale cialis rx order lasix viagra bangkok cheapest cialis prices online viagra cialis vendors buy soma online clomid sale buy cheap lasix online viagra free sample cialis in us viagra canada buy cialis from us soma no prescription cialis pill buy soma buy viagra in us soma for sale where to order viagra viagra buy drug viagra buy cialis in uk synthroid cheap cheap generic cialis buy cheap synthroid online discount propecia acomplia pharmacy order lasix online buy cialis in us soma without a prescription cheap propecia tablets cheap viagra tablets find cheap cialis cialis sales clomid online stores clomid prices compare viagra prices online cheap cialis no rx lasix without prescription cialis pills cialis purchase online pharmacy viagra buy cheap accutane find viagra on internet cialis order buy viagra cheap cheapest levitra cost of viagra cheap lasix tablets order cialis on internet order viagra in canada zithromax no prescription lowest price zithromax cheapest viagra prices