Javascript add text fields

I am trying to add a functionality similar to adding an attachment to
an email in Gmail.

I have a form to create object1. One field is to add a book
reference. When you click the link “add book” a popup opens with the
book form. Clicking the “add” button closes the popup and puts the
title of the book in a text field associated with the book in
object1’s form.

Now, I would like to add the functionality that another text field
will appear with a link saying “add book” to open the popup again.
How can I do that? I eventually also want to have the possibility of
deleting the book reference.