Jump to content

Add Form Fields Dynamically??? Desperate


cmaclennan

Recommended Posts

Hi Guys,

 

I'm desperate for some help at this point, I have a php form that submits to a database and a portion of this form is to caputer serial numbers however the way i currently have it will add as many rows/fields as i need but only submits upto the first 9 for some reason and i really need some help with either figuring out why or coming up with an alternate solution. Any help would be hugely appreciated.

 

Thanks

Link to comment
Share on other sites

<script language="javascript">
		//add a row to the rows collection and get a reference to the newly added row
			var partsRowCount = 1; //stores the number of rows

		//add a new row to the table
		function addRow()
		{
			var namePrefix = "_" + (+partsRowCount + 1); //setup the prefix variable

			partsRowCount++; //increment the counter

			//add a row to the rows collection and get a reference to the newly added row
			var newRow = document.all("orderentry").insertRow();

			//add 3 cells (<td>) to the new row and set the innerHTML to contain text boxes

			var oCell = newRow.insertCell();
			oCell.innerHTML = "<input type='text' name='partid" + namePrefix + "'>";

			oCell = newRow.insertCell();
			oCell.innerHTML = "<input type='text' name='quantity" + namePrefix + "'>";

			oCell = newRow.insertCell();
			oCell.innerHTML = "<input type='text' name='desc" + namePrefix + "'>";

			oCell = newRow.insertCell();
			oCell.innerHTML = "<input type='text' name='serial" + namePrefix + "'>";			
		}

		//deletes the specified row from the table
		function removeRow(src)
		{
			/* src refers to the input button that was clicked.	
			   to get a reference to the containing <tr> element,
			   get the parent of the parent (in this case case <tr>)
			*/			
			var oRow = src.parentElement.parentElement;		

			//once the row reference is obtained, delete it passing in its rowIndex			
			document.all("orderentry").deleteRow(oRow.rowIndex);		
		}

	</script>

Link to comment
Share on other sites

Nothing stnds out as to why the field names wouldn't work past 9, but there are other issues.

 

1. That code will not work in browsers other than IE. You will need to create the fields using DOM (not just innerHTML). I don't have any code handy at the moment, but a little google searching should find a solution.

 

2. You shoudl just create all the field names as arrays and don't worry about adding an index number.Of course if you need to assign an id to the fields, then you do need an index for those, but not the field names. I.e.:

name="fieldName[]"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.