1
People I am trying to do a validation line by line on a table as follows: If the product is marked as yes on a supplier it cannot be marked to another supplier. Can someone please help me? Follow the model...
$("button").click(function() {
$('#selectProduto').change(function(){
$('#msg').html('');
});
var vIdProduto = $('#selectProduto option:selected').val();
var vProduto = $('#selectProduto option:selected').text();
var mensagem = $('#msg');
var linha = '<tr class="selected" id="linha' + vIdProduto + '">' +
'<td>' +
'<input class="idprod" type="hidden" name="idproduto' + vIdProduto + '" value="' + vIdProduto + '">' + vProduto +
'</td>' +
'<td>' +
`<select class="form-control" id="autoriza">
<option value="">Comprar</option>
<option value="Sim">Sim</option>
<option value="Não">Não</option>
</select>`+
'</td>' +
'<td>' +
`<select class="form-control" id="autoriza">
<option value="">Comprar</option>
<option value="Sim">Sim</option>
<option value="Não">Não</option>
</select>`+
'</td>' +
'<td>' +
`<select class="form-control" id="autoriza">
<option value="">Comprar</option>
<option value="Sim">Sim</option>
<option value="Não">Não</option>
</select>`+
'</td>' +
' </tr>'
if($("tr#linha" + vIdProduto).length === 0) {
$('#mytbody').append(linha);
} else {
$('#msg').html("<b class='text-danger'>⚠ Produto " + vIdProduto + " já foi adicionado!</b>");
}
});
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-10">
<select class="form-control" id="selectProduto">
<option value="A">Produto A</option>
<option value="B">Produto B</option>
<option value="C">Produto C</option>
</select>
</div>
<div class="col-md-2">
<button type="button" name="button">Adicionar</button>
</div>
<div class="col-md-12">
<span id="msg"></span><br>
</div>
<div class="col-md-12">
<table class="table table-striped">
<thead>
<tr>
<th>Produto</th>
<th>Forn01</th>
<th>Forn02</th>
<th>Forn03</th>
</tr>
</thead>
<tbody id="mytbody">
</tbody>
</table>
</div>
</div>
</div>
Could you explain your problem better? I’m confused in your question rsrs.
– Pedro Paulo
Thanks for the feedback, I can. I can’t let the system accept that the user buys the same product from different suppliers, right? Ex: If it scores yes in select forn01 select forn02 and forn03 will have to be no or desbilitar understood?
– frodrigues
Guy your code is liable to generate problems, are repeating the ids of
selects
servants.– LeAndrade
Thanks for the return Leandrade , I will correct.
– frodrigues