AW: [Javascript] Re: <select> focussieren

Roger Roelofs rer at datacompusa.com
Tue Feb 8 12:52:39 CST 2005


Laurent,

On Feb 8, 2005, at 9:53 AM, Laurent Muchacho wrote:

> Hi
>
> Just to make the things a bit clear as you went a bit the wrong way to 
> find
> your solution.
> Putting the code after the form was the right approach.
>
> 1) You don't need to use getElementById as your in a form you can 
> simply do
> document.reparatur.art and this work in all browser as it is part of 
> the
> form document object.
> 2) to focus simply do document.reparatur.art.focus()
> 3) On the initial request I think our friend wanted to select one 
> option as
> well document.reparatur.art.selectedIndex = 2

Just to add a bit more clarification...

Putting the code after the form works, but isn't the best approach 
because someday the form will be moved elsewhere in the file, or copied 
to another page and the script will get left behind, or the page will 
get converted to xhtml strict...  (fill in a dozen other scenarios)

Keeping markup, style (css), and behavior (js) in separate files has 
been a major boost to the long term usability of my code.  Having to 
write the same thing over and over is boring and inefficient.

Using getElementById is very useful in this context because often ui 
widgets are shared between forms in the same application.  Not having 
our code tied to a particular form can save work in this type of 
environment.

There are many ways to write javascript code, and sometimes the quick 
'n' dirty approach is the way to go, but I can't count the number of 
times that a page that was requested as a one-off has lived for years 
and had to be altered many times.  It usually starts by a department 
head saying 'You know that web page we use for 'x'?  We need to do the 
same thing with 'y' but it has to do 'z' as well.  Its just a simple 
edit, it shouldn't be hard...' In short, think about tomorrow while you 
write today's code.


Roger
-------------------------------------------------------
Roger Roelofs                 web   www.datacompusa.com
Datacomp Appraisal Services   web   www.mhvillage.com
3215 Eaglecrest Drive, NE     Email rer at datacompusa.com
Grand Rapids, MI  49525-4593 
  




More information about the Javascript mailing list