0
Basically, I have a button that adds two fields when clicked, an input number and a select:
<div class="geraInput">
<div id="form-conjunto">
<select class="input select mb-1" name="produto[]">
<optgroup label="Selecione o produto">
<?php
foreach ($dados as $produtos):
?>
<option value="<?php echo $produtos['id']?>"><?php echo $produtos['nome_produto']?></option>
<?php endforeach; ?>
</optgroup>
</select>
<input type="number" name="qtd[]" min="0" class="input number" placeholder="Quantidade" required><br/><br/>
</div>
</div>
$(document).ready(function () {
//Ao clicar no botão, adiciona uma nova div de inputs
$('.addInput').click(function () {
//Clona a div e salva na variável clone
var clone = $('.form-conjunto').clone();
//Gera a nova div
$('.geraInput').append(clone);
});
});
I have another script that dynamically takes the value of select so that the input number has a max according to the product selects, I do this via ajax but, jQuery is only taking the value of the first select and replicating in all inputs.
$('.select').change(function () {
var max = $('.select').val();
$.ajax({
type: 'GET',
url: 'AjaxReq/baixa.php',
data: {id: max},
success:function (html) {
$('select').parent().find('.number').attr('max', html);
}
});
});
It worked, I changed the 2 selectors for this. Thanks
– Patrick Nascimento