I have a form that generates new input fields via JavaScript on click.
the inputs are successfully added to the FORM with the desired naming convention.
<input type="text" name="util_name0" id="util_name0" value="" /><br/>
<input type="button" onClick="newUtil(this)" value="Add New" />
newUtil() adds:
<input type="text" name="util_name1" id="util_name1" value="" />
however after posting, print_r($_POST) only lists ‘util_name0‘.
Normally i’d paste some code, but that’s all i really need to do at this point…
form is in an include called from parent.php.
Javascript is called in parent.php
JS:
function newUtil(el) {
var newval = util_count++;
$('#qty').attr('value', newval);
$(el).before('-------------<br />
<div class="newUtilField">
<label for="util_type'+newval+'">Type (i.e. gas, electric...) '+newval+'</label><br />
<input type="text" name="util_type'+newval+'" id="util_type'+newval+'" value="" /><br /><br />
<label for="util_name'+newval+'">Company Name</label><br />
<input type="text" name="util_name'+newval+'" id="util_name'+newval+'" value="" /><br /><br />
<label for="util_number'+newval+'">Company Number</label><br />
<input type="text" name="util_number'+newval+'" id="util_number'+newval+'" value="" />
</div><br /><br />');
}
After execute the js code that adding the new field, inspect the new element using Firebug (in Firefox) or Web Inspector (in safari and google chrome). If the new field is outside the
formtag, then it will not be included to form submit.If you can, please provide the structure of
formand it’s fields. Also, make sure that the page contain no other error, and the tag is well balanced, all open tag have been closed in the right place. Misplace closing tag might yield error and unexpected behaviour.