Create a Modal to Add new fields dynamically I have to develop a contest page. Every participant may have one or more codes that can use to participate in the event. After that the user must fill a form with their personal data so they can be contacted  in case they win the contest.

How could I add a [+] button that opens a modal window asking me how many code field would I need? If I write 5 for example, we create dynamically 5 code fields to the input. 

I managed to create an add more button that add just one more button, but for clients requirements, we need to use a popup that ask how many fields we need.
I am not sure how this can be done entirely with Webforms. One option is to include in this webform all necessary fields, including the ones that would appear as a modal dialog. Even better, group these as a fieldset. 

Then in a custom module or theme include some jQuery logic with which would be very easy to create a modal dialog in the same page. There is a dialog widget in jQuery UI and this is a relevant question in SO.