1
I need to create a select with values from 1 to N numbers. After the user selects a number in select I have to clone the div lote
from the selected value.
Example: if I select number 2 in select, you have to clone two Divs. If I select 1, clone only one and I select 3 clone 3.
Follow an example:
$("#qtdLote").on("change",function(){
var num=parseInt($(this).val());
//$("#grupo-lotes").html(''); //limpar antes de gerar
for(var i=1;i<=num;i++){
$("#grupo-lotes").append($("#lote").clone());
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<label>Escolha</label>
<select id="qtdLote">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
</div>
<br />
<div id="grupo-lotes">
<div id="lote">
<label>LOTE </label>
<input type="">
</div>
</div>
See on the codepen.io
Luciano, your question is a little confused. Your example seems to already answer your question. What exactly do you need to do?
– bio
I don’t understand what you’re needing exactly, do you just want the select number to be dynamic? why it is already cloning, but without overwriting the previous.
– Luigi Azevedo
This it clones but does not overwrite, it has to be dynamic ex: I selected 2 then it has to appear two cloned Ivs
– Luciano Ramos