ok. so I am trying to create a form so that, when I a button "+" a new form appears beneath the existing one. For example I have form to fill name
VoteType
name: [ ]
{+} -- (button)
when clicked "+" the form will look like this
VoteType
name: [ ]
Vote1 name [ ]
image [ ]
date [ ]
{+} -- (button)
and the button "+" so that I can add Vote2 ... as many as I want.
So I did this form buy when I try to number them, the numbers don't go as I intended.
<fieldset id="fieldset">
<form method = 'POST' action = ''>{%csrf_token %}
<p>{{ voteTypeForm }}</p>
</form>
<div id="placeholder">
<div id="template">
<p><fieldset id="fieldsets">
<legend id="legends">Candidate No <input type="text" id="someInput" name="someInput" readonly></input></legend>
<form method = 'POST' action = ''>{%csrf_token %}
{{ voteForm.as_p}}
</form>
</fieldset></p>
</div>
</div>
<p><button type="button" name="Submit" onclick="Add();">+</button></p>
<input type = 'submit' value="create"/>
</fieldset>
<script>
var _counter = 0;
function Add() {
_counter++;
var oClone = document.getElementById("template").cloneNode(true);
oClone.id += (_counter + "");
document.getElementById("placeholder").appendChild(oClone);
document.getElementById("someInput").value = _counter;
}
</script>
When I click button + it creates forms but numbers them like this:
4 [empty] 1 2 3
instead of
1 2 3 4 5
I was trying to somehow hide the placeholder using style "none"
, but than it didn't show any of them, than I tried to activate it only when counter is more than 1 but than it showed first one again. I don't usually use javascript so please help. How can I solve this?