开发者

JavaScript injected form field does not appear in POST data

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="te开发者_Python百科xt" 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 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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜