Running code in a form before clicking submit?

How do I get a form to partially run before clicking the submit button?

As users are filling in a form, they submit an interger answer, eg. 4, how do I generate 4 rows to be filled in before they’ve clicked submit?