I want to add a complete div including at least one "sub-div" as shown in my example code. It is quite easy:
- I need an "add LP" button on LP-DIV level
- I need an "add AP" button on AP-DIV Level
- Each new added LP should look like the first one (with 1 AP1)
- There should be the Option to remove LP or AP Elements completely when added accidentally.
- Dynamically added data is to be stored in a database afterwards (how do I pass the Elements Content within the form ?)
I hope you can help me with this issue. I know the code example is not very nice and not optimized but I needed to reproduce my complex issue within a bigger project for simple understanding.
I already tried jQuery's append
and prepend
and I found examples showing how to dynamically add elements when you have just one input. I didn't find any example for my issue.
<!doctype html>
<html>
<head>
<title>Form with nested workpackages</title>
</head>
<body>
<div class="container">
<form>
<div id="LP1div" style="border:1px solid black;background:#888888;width:90%;margin:5px;padding:5px;">LP1 div <br />
<input type="text" class="form-control" id="lp1nameinput" placeholder="<lp1name>">
<input type="text" class="form-control" id="lp1typinput" placeholder="<lp1typ>">
<input type="text" class="form-control" id="lp1summeinput" placeholder="<lp1summe>">
<div id="LP1AP1div" style="border:1px solid black;background:#81F7F3;width:75%;margin:5px;padding:5px;">LP1 AP1 div <br />
<input type="text" class="form-control" id="lp1ap1nameinput" placeholder="<lp1ap1name>">
<input type="text" class="form-control" id="lp1ap1typinput" placeholder="<lp1ap1typ>">
<input type="text" class="form-control" id="lp1ap1summeinput" placeholder="<lp1ap1summe>">
</div>
<div id="LP1AP2div" style="border:1px solid black;background:#58ACFA;width:75%;margin:5px;padding:5px;">LP1 AP2 div <br />
<input type="text" class="form-control" id="lp1ap2nameinput" placeholder="<lp1ap2name>">
<input type="text" class="form-control" id="lp1ap2typinput" placeholder="<lp1ap2typ>">
<input type="text" class="form-control" id="lp1ap2summeinput" placeholder="<lp1ap2summe>">
</div>
</div>
<div id="LP2div" style="border:1px solid black;background:#CCCCCC;width:90%;margin:5px;padding:5px;">LP2 div <br />
<input type="text" class="form-control" id="lp2nameinput" placeholder="<lp2name>">
<input type="text" class="form-control" id="lp2typinput" placeholder="<lp2typ>">
<input type="text" class="form-control" id="lp2summeinput" placeholder="<lp2summe>">
<div id="lp2AP1div" style="border:1px solid black;background:#81F7F3;width:75%;margin:5px;padding:5px;">lp2 AP1 div <br />
<input type="text" class="form-control" id="lp2ap1nameinput" placeholder="<lp2ap1name>">
<input type="text" class="form-control" id="lp2ap1typinput" placeholder="<lp2ap1typ>">
<input type="text" class="form-control" id="lp2ap1summeinput" placeholder="<lp2ap1summe>">
</div>
<div id="lp2AP2div" style="border:1px solid black;background:#58ACFA;width:75%;margin:5px;padding:5px;">lp2 AP2 div <br />
<input type="text" class="form-control" id="lp2ap2nameinput" placeholder="<lp2ap2name>">
<input type="text" class="form-control" id="lp2ap2typinput" placeholder="<lp2ap2typ>">
<input type="text" class="form-control" id="lp2ap2summeinput" placeholder="<lp2ap2summe>">
</div>
</div>
</form>
</div>
</body>
</html>