No properties?

U

UKuser

Hi,

I am using AJAX to post an update to a PHP script and database. The
php then displays a list of input boxes with the newly updated
entries. If I process it by going Add an entry then Remove an entry
it works fine and I get no errors, however if I go Remove an entry
then Add an entry I get the following error:

document.getElementsByName("prop[" + i + "]")[0] has no properties

However using this sample code I found on the web:

for(i=0; i<document.f1.elements.length; i++)
{
document.write("The field name is: " + document.f1.elements.name +
" and it's value is: " + document.f1.elements.value + ".<br />");
}

I get the following for the prop field:
The field name is: prop[0] and it's value is: test6.

In short something in the order I'm doing my db updates is upsetting
the add.js however the field clearly has properties and using
alert(document.getElementsByName("prop[0]")[0].value) also displays
the fields value.

Why would one method be finding the fields value, but my simple for
method below not?

for (i = 0; i < ct; i++)
{
name = document.getElementsByName('prop['+i+']')[0].value;
prop = document.getElementsByName('properties['+i+']')
[0].value;
pid = document.getElementsByName('pid['+i+']')[0].value;
test = name+'^'+prop+'^'+pid+'|';
}

Any help/advice would be great.

Thanks

A
 
M

Martin Honnen

UKuser said:
document.getElementsByName("prop[" + i + "]")[0] has no properties

However using this sample code I found on the web:

for(i=0; i<document.f1.elements.length; i++)
{
document.write("The field name is: " + document.f1.elements.name +
" and it's value is: " + document.f1.elements.value + ".<br />");
}

I get the following for the prop field:
The field name is: prop[0] and it's value is: test6.


What is the value of the variable i? Unless it is 0 that test you do
does not tell us much as having a field with name 'prop[0]' does not
help if i is 2 for instance as then your getElementsByName('prop[2]'])
call looks for different elements.
 
U

UKuser

UKuser said:
document.getElementsByName("prop[" + i + "]")[0] has no properties
However using this sample code I found on the web:
for(i=0; i<document.f1.elements.length; i++)
{
document.write("The field name is: " + document.f1.elements.name +
" and it's value is: " + document.f1.elements.value + ".<br />");
}

I get the following for the prop field:
The field name is: prop[0] and it's value is: test6.

What is the value of the variable i? Unless it is 0 that test you do
does not tell us much as having a field with name 'prop[0]' does not
help if i is 2 for instance as then your getElementsByName('prop[2]'])
call looks for different elements.


Hi there,

It is supplied to the function
onclick="ajaxFunction($pid,'$prop','$t1');" in this example as $t1.

The number definitely makes it through to the script, and as I say,
using the form values displays, but even applying the document.forms
method to my for loop doesnt work. The loop is:

for (i = 0; i < ct; i++)
name = document.getElementsByName('prop['+i+']')[0].value;
prop = document.getElementsByName('properties['+i+']')
[0].value;
pid = document.getElementsByName('pid['+i+']')[0].value;
test = name+'^'+prop+'^'+pid+'|';
}

Thanks

A
 
U

UKuser

UKuser said:
document.getElementsByName("prop[" + i + "]")[0] has no properties
However using this sample code I found on the web:
for(i=0; i<document.f1.elements.length; i++)
{
document.write("The field name is: " + document.f1.elements.name +
" and it's value is: " + document.f1.elements.value + ".<br />");
}
I get the following for the prop field:
The field name is: prop[0] and it's value is: test6.

What is the value of the variable i? Unless it is 0 that test you do
does not tell us much as having a field with name 'prop[0]' does not
help if i is 2 for instance as then your getElementsByName('prop[2]'])
call looks for different elements.

Martin Honnen
http://JavaScript.FAQTs.com/

Hi there,

It is supplied to the function
onclick="ajaxFunction($pid,'$prop','$t1');" in this example as $t1.

The number definitely makes it through to the script, and as I say,
using the form values displays, but even applying the document.forms
method to my for loop doesnt work. The loop is:

for (i = 0; i < ct; i++)
name = document.getElementsByName('prop['+i+']')[0].value;
prop = document.getElementsByName('properties['+i+']')
[0].value;
pid = document.getElementsByName('pid['+i+']')[0].value;
test = name+'^'+prop+'^'+pid+'|';
}

Thanks

A


And just to add - doing alert(test) within the for statement
CORRECTLY returns each of the listed items. In short - there IS a
value within each element - but apparently no properties??
 
T

Thomas 'PointedEars' Lahn

UKuser said:
I am using AJAX to post an update to a PHP script and database. The
php then displays a list of input boxes with the newly updated
entries. If I process it by going Add an entry then Remove an entry
it works fine and I get no errors, however if I go Remove an entry
then Add an entry

How do you "add" and "remove" "an entry"? What is "an entry" anyway?
I get the following error:

document.getElementsByName("prop[" + i + "]")[0] has no properties

Probably because that is so (the value is `null' or `undefined'). It is
seldom necessary to use gEBN() for form controls, though.

document.forms[...].elements[...]
However using this sample code I found on the web:

for(i=0; i<document.f1.elements.length; i++)

Should be at least

for (var i = 0, f, len = document.forms["f1"].elements.length;
i < len; i++)
{
document.write("The field name is: " + document.f1.elements.name +
" and it's value is: " + document.f1.elements.value + ".<br />");


Same here. And dump XML syntax if you don't use XHTML. And use HTML
if you don't need XHTML.
}

I get the following for the prop field:
The field name is: prop[0] and it's value is: test6.

In short something in the order I'm doing my db updates is upsetting
the add.js however the field clearly has properties

Parse error.
and using alert(document.getElementsByName("prop[0]")[0].value) also
displays the fields value.

Why would one method be finding the fields value, but my simple for
method below not?

for (i = 0; i < ct; i++)
{
name = document.getElementsByName('prop['+i+']')[0].value;
prop = document.getElementsByName('properties['+i+']')
[0].value;
pid = document.getElementsByName('pid['+i+']')[0].value;
test = name+'^'+prop+'^'+pid+'|';
}
[...]


You don't tell what `ct' is, how the processed markup looks like and what
test yields.

The only thing I can think of is that the form control has no name, but it
has an ID. It would then be a peculiarity of the used DOM implementation
(that you don't tell either) to yield the element's ID when the `name'
property is accessed. However, that does not explain why you think
document.getElementsByName("prop[0]")[0].value yields "the fields value",
unless this is another peculiarity.

Please take heed of http://www.jibbering.com/faq/faq_notes/clj_posts.html


PointedEars
 

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

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,250
Latest member
Charlesreero

Latest Threads

Top