0

I have a script that successfully adds input fields based on a users selection.

For example

<input name=test[] value="1">
<input name=test[] value="2">

However, when the form is submitted these values (array) do not show up in the post.

If I add them to the html it works so is clearly a result of the html having been added to the DOM by javascript.

I have also tried $('name[coupon]').serialize().replace('%5B%5D', '[]'); on submit (where coupon is the name of the form) - but no joy!

Any advice please?

peterflynn
  • 4,667
  • 2
  • 27
  • 40
  • Do each of these dynamically added input controls have unique names? Per HTML specification, the value of a form input control will not be posted to the server if it does not have a name. – Brett Oct 31 '13 at 16:29
  • Yes - they have names as shown in the code example above. The issue seems to be the fact that I am adding names with square brackets at the end.... if I remove these all is OK - but that of course remove the array capability...... – user2942258 Oct 31 '13 at 16:34
  • You should add quotes around the name - but it also works without them. The problem must be somewhere else. Perhaps paste the complete code. – Petra Oct 31 '13 at 17:05
  • 1
    A fiddle would be helpful. – ach Oct 31 '13 at 17:06
  • Hi - my earlier observation was wrong - it is not working without square brackets either! Below is the DOM AFTER I have added code When I post the input fields with test[] are picked up - these were part of the hard coded html. The input field with test1 (which was added by jquery) is not picked up. If I add another input field with test[] I only see the origional two at the POST stage – user2942258 Oct 31 '13 at 17:17
  • OK - from another post I have found a solution - though not sure why! IF I append the new html to the form rather than a div within the form it works! – user2942258 Oct 31 '13 at 17:31
  • That shouldn't matter *if* you are appending it correctly. You didn't post enough *clear* information about your specific problem. – Brett Nov 01 '13 at 18:39

0 Answers0