[thelist] DOM question

Stephen Caudill SCaudill at municode.com
Fri Dec 6 14:02:01 CST 2002


PPK to the rescue!
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> Don't rewrite it. formName.elementName is the Level 0 DOM,
> which means that
> it'll work in all JavaScript browsers. getElementById, on the
> other hand,
> only works in the modern browsers. So formName.elementName is
> the better
> choice.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Okay.  makes that a little easier.


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> Besides, if you want a random element of the form, you should do
>
> document.formName.elements[randy].value
>
> since 'elementName' is the name of one specific element, and
> unless the
> element is a set of radio buttons it's not an array (unless
> you use a lot of
> form fields with name 'elementName'.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
I do, I had an ASP routine do a DB query for accounts with populations exceeding 250,000 and print them all in named hidden fields, which I am then calling into the javascript to display to screen with a fade in, fade out effect...  Sounds kinda bootleg in retrospect.


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> There is (should be) only one element with a specific ID.
> getElementById
> doesn't return an array, like getElementsByTagName() does. Instead it
> returns the single element with the correct ID.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
missed that, I wrote the fields dynamically(do until .eof, loop), so I didn't think about the fact there would be more than one id...


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> >	var randy = Math.round(Math.random() * max)
>
> Has this variable been initialized before you use the
> document.formName.etc?
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
err... yes.  Is that bad?

Thanks,
Stephen



More information about the thelist mailing list