Forum Moderators: open
for(var i=0; i<a; i++)
{
text="fname"+i;
full=document.fo.text.value;
}
So it give the famous error:
document.fo.text.value(null or has no value) so is there specia concatenation for the "text" cuz its real value is fname0.
btw i checked viewSource and the field name actually name is fname0
thanks in advance
for(var i=0; i<a; i++)
What this means is:
1. Set the value of the variable "i" to zero.
2. As long as "i" is less than "a" do the block below.
3. Add 1 to the value of "i".
But you've never defined "a", so "a" is effectively equal to zero. So "i" will *never* be less than "a". So the code block will never execute.
text="fname"+i;
This produces a string such as "fname0" or "fname1". It doesn't get any value from a form field, if that's what you were trying to do. And it won't actually run anyway as mentioned above.
full=document.fo.text.value;
This sets the value of the variable "full" to the value of the field "text" in the form called "fo". But it won't actually run either, as mentioned above.
Actually, if you're getting the error message you mentioned, then maybe you defined "a" elsewhere so your IF block actually runs, but since you posted incomplete code I can't really see what's going on.
Anyway, the way to reference the value of a field is:
document.form.field.value
Replace "form" with the name of the form, and "field" with the name of the field. Or, you could name your form "form" and your field "field".
Hope this helps.
so now in this example:
document.form.field.value
my field name is dynamic so its equal fname0, fname1 and so on.
my question is.. whats wrong in this?
i=0;
field=="fname"+i;
full=document.form.field.value; //I get error here Null or no value.
full = document.form["fname" + i].value;