accessing form elements length

L

lasher168

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
 
R

Richard Cornford

lasher168 wrote:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top