Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple form fields/Same name

Status
Not open for further replies.

TCavins

Programmer
Aug 8, 2001
25
US
I am trying to append text from different fields on the form to hidden fields in the form. The form fields I am combining in javascript and setting them to the variable descr.

I want to append descr to a field on the form. The field(QuestionDescription) is in the form more than once so Javascript reads it as an array.

Here is the code that I am working with. I am unable to append descr when the form is submitted. Only the existing value of the array is being passed. Any help would be appreciated.

-Tim

function blah(f){
var descr = f.Description1.value + ' ' + f.Description2.value;

for(var i=0; i < f.QuestionDescription.length; i++)
{
if(i==0)
{
QuestionDescription = f.QuestionDescription.value;
}
else
{
QuestionDescription = QuestionDescription + ','+ f.QuestionDescription.value;
}
}
//QuestionDescription now holds the values of the formfield
//I am trying to append a new line to it with the following:

f.QuestionDescription.value = QuestionDescription + ',' + descr;

alert(f.QuestionDescription.value);
}




 
Your code was gobbled up by the TGML (always turn that off when dealing with arrays!), but I think I might understand what your problem is. Try using:

f.QuestionDescription.value += QuestionDescription + ',' + descr;


jared@eae.net -
 
Jared,

Thanks for your help. However, I am still getting the same error. Since QuestionDescription is an array, f.QuestionDescription.value is null so I can't just append it like f.QuestionDescription.value += ',' + descr;

I have to find a way to append an item to the array and have the form process that I think but so far I have been unsuccessful at it.

-Tim
 
Jared,

I fixed it a different way.I added an additional hidden field in the form named QuestionDescription with a value of &quot;&quot;.

In javascript I took the last element of the array and reset it to descr.

It was actually an easy fix, I just never thought of doing it like that.

Thanks for your help.

-Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top