You don't need code to do this.
Use Data->Default Values for your list box and add a bunch of blank ones. Add a conditional formatting to only show non blank. Add a rule to your button to set the value of the last list box row to the value of the dropdown. Use the xpath Count(../preceding-sibling::my:myListBox)+1 to get the last one (Note: myListBox) should be replaced with the correct field name for the repeating group node in your data source and you should be using a repeating group with a non repeating field underneath it for your list box - do not use a repeating field in a non-repeating group).
If having blank rows bugs you, you can use qRules to insert one at a time when they click the button.