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
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