I am trying to make a dynamic form using Spring forms. Basically, the form gets the name of the learning activity, and then a button appears below it, which says: "Add another learning activity." This allows the user to add another learning activity. I want him to add as much as he wants.
I have not tried this before, so obviously I ran into errors with the first solution I was thinking about. I really had the feeling that what I did would lead to an error, but just make the drive home, what I'm trying to do, here is the code:
<script language="javascript"> fields = 0; function addInput() { document.getElementById('text').innerHTML += "<form:input path='activity[fields++].activity'/><br />"; }
<div id="text"> <form:form commandName="course"> Learning Activity 1 <form:input path="activity[0].activity"/> <input type="button" value="add activity" onclick="addInput()"/> <br/><br/> <input type="submit"/> </form:form> <br/><br/> </div>
java javascript spring spring-mvc
Jeune
source share