[Javascript] required entry field

TomMallard mallard at serv.net
Fri Mar 28 22:34:14 CST 2003


Aha!! VBScript errors...arrays use parens () and have an item collection so
item(0) is the first element. Pretty easy mistake when you write both
languages and it's late.

tom mallard
seattle

-----Original Message-----
From: javascript-bounces at LaTech.edu
[mailto:javascript-bounces at LaTech.edu]On Behalf Of David T. Lovering
Sent: Friday, March 28, 2003 4:21 PM
To: [JavaScript List]
Subject: Re: [Javascript] required entry field



> All items inside the form object become slaves or somekind of captives by
> form individual, their names or IDs will not be processed, and will have
no
> rights to speak in their names, only the form master will act as
> representative and is allowed to communicate with them.
> Because of that, you will have to ask the Form waht is the name or the
value
> of the item(x).

Damn straight!  This is a GOOD thing!!!

> function isValid() {
> if(myForm.NeverBlank.value=='')
>    {
> myForm.item(0).focus() //if first input in the collection
>     document.forms(0).item(0).focus()//if first form in the document
(uggly
> and very unoptimized)
>    }
> }

Nope.  Sorry -- but arrays are indexed by square brackets "[ ]", not
parentheses "( )".  This will die
gloriously.  Also, some browsers get ornery when you start playing fast and
loose with the document prefix, particularly if you done something funky
with your default window name.

Where did this item(0) [sic!] jazz come from?  Perhaps you mean 'element[0]'
for the first object inside the form.
This is dangerous if you put something (like a radio button or whatever)
ahead of the text input. Try the syntax I outlined in my most recent message
before this one.

> So these are the ways one can access inputs (items) inside the form:
>
> a. doument.forms(n).item(n) //'n' stands for numeric value
> b. myForm.item(n)
> c. myForm.NeverBlank

Zero for zero.  Try

  document.forms[m].element[n]
  document.myForm.element[n]
  document.myForm.NeverBlank

If 'n' and 'm' are actually variables, you'll have to do it like this (on
most browsers):

  var myObject = eval('document.forms[' + m + '].element[' + n + ']');
  var myObject = eval('document.myForm.element[' + n + ']');

>
> But the best is the last.(it executes faster) 3x, if only one form in the
> document and only one item in the form, and as the number increases the
> difference of speed follows by multiplying the starting difference of
speed
> compared with [a] choice. And it's more scripter-firendly.

Not surprising.  The fewer substitutions that the JavaScript engine has to
make,
the faster the whole thing will run.

-- Dave Lovering
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list