Jump to content

[solved]array From Form Values


johnnyg24

Recommended Posts

I have a form where a user can add an unlimited number of entries. These entires consist of 3 input fields. I have a script that automatically assigns a new name to each reoccurring input field. For example, lets say for entry one my input names are A1, B1, C1. When a user adds another entry, the script then assigns the new entry's input names to A2, B2, C2. This will go on for however many entries a user enters. What I am looking to do is create 3 hidden input fields where and array of this information will be stored and then submitted to our server which will split it and do what it needs to do. Array[a] would be all the names that being with "A", Array would be all the names that begin with "B" and Array[c] would be all the name start being with "C".My question is how would I loop through all of these input names when I don't know how many will be entered before submitting.I would like the array to be build after the user selects submit. This is because the user has the option of removing certain entries before they submit and the script is currently renaming all the names so they are sequential. Any help would be appreciated.Solved(well kind of): Our server will sort it all out.

function insert(val){	array[array.length]=val;}function elmLoop(){array = new Array();var theForm = document.forms[1]   for(i=3; i<theForm.elements.length; i++){		var alertText = ""		alertText = theForm.elements[i].name		if(theForm.elements[i].type == "text"){			alertText += "=" + theForm.elements[i].value		}		else if(theForm.elements[i].type == "checkbox"){			alertText += "=" + theForm.elements[i].checked		}		else if(theForm.elements[i].type == "button"){			alertText += "!"		}	   			  insert(alertText)   }   alert(array);}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...