accessing form elements length

Discussion in 'Javascript' started by lasher168, May 30, 2006.

  1. lasher168

    lasher168 Guest

    Hi,

    I have a problem which I have been on pondering all day and wasting
    time !!!

    I have a javascript call which looks like this

    <td width="50%" class="inputLabel"><span class="mainTitle">Ship
    To</span><input
    name="sameasbillto" type="checkbox"
    onclick="copyAddress(this.form);">
    Same as Bill To
    </td>

    the javascript looks like this

    function copyAddress() {

    var form = document.forms[0];

    alert("do i get here");

    if (form == null) {
    return;
    }

    alert("This is form "+form.fulfilment.value);
    alert("This is form "+form.productName.value);

    alert("This is element "+form.elements.length);

    I cannot work out why I cannot get the length of the elements.

    If I did this

    alert("This is element "+form.elements.length);

    the popup says this --> element [object]

    If I typed this

    alert("This is element "+form.elementname.value);

    I get the correct answer.

    All the above does not work in IE but works perfectly in firefox

    Thanks

    Chris
    lasher168, May 30, 2006
    #1
    1. Advertising

  2. lasher168 wrote:
    <snip>
    > I cannot work out why I cannot get the length of
    > the elements.
    >
    > If I did this
    >
    > alert("This is element "+form.elements.length);
    >
    > the popup says this --> element [object]

    <snip>

    You have a control in your form with the name 'length' and you are
    getting a reference to the form control back from -
    form.elements.length - instead of the length of the collection. You need
    to change the name of the control so that it does not correspond with
    the names of an form or form.elements properties.

    Richard.
    Richard Cornford, May 30, 2006
    #2
    1. Advertising

  3. lasher168

    lasher168 Guest

    thanks for that i didnt see that
    lasher168, May 30, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mitchua
    Replies:
    5
    Views:
    2,736
    Eric J. Roode
    Jul 17, 2003
  2. =?Utf-8?B?SG96aQ==?=
    Replies:
    1
    Views:
    6,954
    Ken Cox [Microsoft MVP]
    Jun 2, 2004
  3. Gerald Aichholzer
    Replies:
    2
    Views:
    2,499
    Gerald Aichholzer
    Jun 27, 2006
  4. Replies:
    3
    Views:
    100
    Dr John Stockton
    Apr 2, 2006
  5. Replies:
    4
    Views:
    184
Loading...

Share This Page