views:

209

answers:

3

hey guys. 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 />');
}
A: 

Would recommend creating proper objects rather than creating the elements like that. Create elements and inject them one by one.

EDIT : check link http://domscripting.com/blog/display/99

Zaje
A: 

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 form tag, then it will not be included to form submit.

If you can, please provide the structure of form and 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.

Donny Kurnia
uggggghhhhh... ok guys, i am ashamed to admit Donny Kurnia was absolutely right :) (no offense... i'm mad at myself). i wrapped my form tags horribly improper.... sorry and thanks. :\
worldthreat
A: 

Is this behaving differently in IE than it is in Firefox? Run an HTTP sniffer (like Fiddler) on it check the HTTP post headers carefully.

hinghoo