Jump to content

[solved]array From Form Values


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);}

Edited by johnnyg24
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...