Edit: I fixed the problem, just starting from scratch. Sorry to waste time. Please vote to close if you feel so addicted.
I'm having trouble getting the actual data in the form to submit when input fields are added via javascript. Fields are displayed in the right place, but when I do var_dump (field name) on the server side, nothing appears. Checking with Live HTTP headers tells me that the browser is not trying to send dynamically added form fields.
Do I need to somehow "attach" my dynamically created input form forms to the form?
My code is:
HTML
<form id="att_form" method="post" name="add_attachments" enctype="multipart/form-data" action="#"> <-- below input to prove form submits, just not the dyn added elements --> <input name="data[one]" type="text" /> <div id="add_fields"></div> <input type="submit" /> </form>
Javascript
function addFormField() { var id = 1; var htm = "<p id='row" + id + "'><input type='text' size='20' name='txt[]' id='txt" + id + "' /></p>"; $("#add_fields".append( htm ); }
When I submit the form, my input named data [one] is displayed as the POSTd value, but those added with addFormField () do not. They are displayed in HTML, in the right place, but not POST. Do I need to add an element as a child to a form element in order to submit it?
I saw Submit form input fields added using javascript , where I got the idea of โโadding data directly to the child form, but this will require some restructuring of my CSS. So, I hope this is something simple that I can do in the code above.
Thanks in advance!
edit: typos fixed, but still not working. I decided to use the library free JS method discussed in the SO link above, as this works fine. Thanks for the help though!
javascript jquery html php
Travis leleu
source share