Re: How do you access the previous field in a form?

by Ed Lazor <osmosis(at)atfantasy.com>

 Date:  Tue, 28 Nov 2000 12:25:39 -0800
 To:  andy dunbar <krone9(at)yahoo.com>
 Cc:  hwg-style(at)hwg.org
 In-Reply-To:  yahoo
  todo: View Thread, Original
At 03:05 AM 11/28/2000 -0800, you wrote:
>I guess the first question I have is - do you really
>need to do it like this?!

Not really, but it sure made things easier =)  Designer's
aren't always programmers.  Now they can alter the
form and the name of their fields all they want and I don't
have to worry whether they remembered to update the
onChange parameters of the select statement.

>the form (I'd need to think about the logic involved
>in that)

num_elements = document.form[0].length;
for (i=0; i<num_elements; i++) {
         if (document.form[0].elements[i].name == this.name)
                 previous_element = i - 1;
}

>if you just want to change an element - eg another
>dropdown select depending  on the input of that select
>then you'd be better off naming the individual
>elements so you can reference them by name rather than
>by their relation to each other.
>
>so erm can we have some more information please 8)

The form in question had a lot of fields and several people
working on it.  Fields were in pairs of one input field and one
select field.  Changing the select field automatically changed
the value of the related input field.

The select statement's onChange parameter originally passed
the update function a reference to itself and the related input
field.  Every time someone changed the name of the input field,
the select statement onChange field would need updating.  This
was being overlooked - a lot.  I noticed the input statement was
*always* followed by the select statement.  I verified this with
the designer, and that's how original idea came up and made
things much easier for everyone involved =)

-Ed

HWG hwg-style mailing list archives, maintained by Webmasters @ IWA