cmaclennan Posted July 28, 2009 Share Posted July 28, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/167822-add-form-fields-dynamically-desperate/ Share on other sites More sharing options...
Psycho Posted July 28, 2009 Share Posted July 28, 2009 Seeing the code you have would help. Quote Link to comment https://forums.phpfreaks.com/topic/167822-add-form-fields-dynamically-desperate/#findComment-885150 Share on other sites More sharing options...
cmaclennan Posted July 28, 2009 Author Share Posted July 28, 2009 <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> Quote Link to comment https://forums.phpfreaks.com/topic/167822-add-form-fields-dynamically-desperate/#findComment-885153 Share on other sites More sharing options...
Psycho Posted July 28, 2009 Share Posted July 28, 2009 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[]" Quote Link to comment https://forums.phpfreaks.com/topic/167822-add-form-fields-dynamically-desperate/#findComment-885171 Share on other sites More sharing options...
haku Posted July 29, 2009 Share Posted July 29, 2009 And this: <script language="javascript"> should be this: <script type="text/javascript"> (the language attribute has been deprecated) Quote Link to comment https://forums.phpfreaks.com/topic/167822-add-form-fields-dynamically-desperate/#findComment-885518 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.