Assign input field values to another value

Hi,

I have a form where attachments can be added.
Those attachment values will be wrapped into html code so it will be links.
As they can click on a + sign to add more input fields, the amount of input fields is dynamic.
For each input tag there is, this value will be written to a hidden form field called “url” before it will be sent to the database.

Now it works and adds data to the database… but not for every form field apparently. Only for 1 new field…


function getAttachmentValues(){
 var field = document.getElementById('wisselvelden').getElementsByTagName('input');
 var attachment = "";
 alert(field.length); // this alerts the correct nr of fields
 for(var i=0; i<field.length;i++){
   if(field[i].name ==='attac' && field[i].value !== ""){
     attachment = "<a href='"+field[i].value+"' target='_blank'>Attachment "+[i]+"<\\/a><br \\/>";
// url document below is a hidden field in the form where the values will be written into
     document.messageform.url.value += attachment;
   }
 attachment = "";
 } alert(document.messageform.url.value); // shows that the url does not contain the values of every input field... :s
}


Anyone had this problem?

Yes,

I believe because the JavaScript isn’t placing a value into the physical DOM (Just the appearance) and when the form is POST, it doesn’t read the updated values, because they are physically not there.

I forgot what you call this type of thing, delegation maybe – but with JQuery I have found this function to work: http://api.jquery.com/live/

I don’t know the JavaScript equivalent.

Strange, because when I make my hidden form field visible then the following happens:
I click on post, the alert appears to show me the value of url.
At this moment, I look at the visible form field where this value is added aswel… exept for the last added attachments.
It’s strange, if you add for example 3 attachments, he adds only the first one.
So he passes values anyway.

I thought there was something in the for loop, but that isn’t :s

Resolved !

apparently, my attribute names in my input tags were name=“attac”.
But by an external function, I added extra input fields with name=“attach”.

Véry stupid mistake of me. :s

sorry to bother you guys, but thanks for the response !