Account services

Bad habits 6: Unnecessary use of Javascript

What is wrong with this code snippet?

  <script type="text/javascript">

          function openPage(action) {

  <form name="f" action="main" method="post">
          <input type="hidden" name="app" value="" />
          <input type="hidden" name="ACTION" value="" />
          <input type="hidden" name="ACL" value="" />

   <li><a href="javascript:openPage('C')"
       title='Show Applications'>Applications</a></li>

The problems

  1. It doesn't work if the user has Javascript turned off.
  2. It doesn't change the url in the address bar in the browser. Therefore the user can't bookmark the "Applications" page.

The replacement

All the code you see above can be replaced with three simple lines:

   <li><a href="main?ACTION=C" title='Show Applications'>Applications</a></li>