a few days ago a partner helps me to transfer the data from a table to a modal, in them there is a select that receives the status according to the value they have and they are selected. Well but now it is more complicated, I carry the name that the field brings but the select is generated by a while of SQL and I do not know how to make it detect the marked name.
With this we send the content of the span to the modal:
<td class="otrotdfgaz" id="select2-2<?php echo $resta['id']; ?>">
<?php
if($resta['idCliente'] == 0) echo "<span>Almacén</span>";
else{
?>
<span><a href="ver-cliente.php?ID=<?php echo $resta['IdUsuario']; ?>"><?php echo $resta['Nombre']; ?></span></a><span>
<?php } ?>
</td>
With this we pass the value to the id of the select, so that it receives the value:
<script>
$(document).ready(function(){
$(document).on('click', '.referencias', function(){
var id=$(this).val();
var Stock=$('#select2-2'+id).children('span').first().text();
$('#referencias').modal('show');
//alert(Stock);
if(Stock == 'Almacén')
$('select#select2-2').val('0').trigger('change');
else
$('select#select2-2').val('<?php echo $res['IdUsuario']; ?>').trigger('change');
});
});
</script>
With this we receive the value:
<select id="select2-2" value="" class="form-control" name="select2-2">
<option value="0">Almacén</option>
<?php
//var_dump($_GET);
$results = $mysqli->query("SELECT * FROM Usuarios");
mysqli_set_charset("utf8");
while($res = $results->fetch_array()) {
?>
<option value="<?php echo $res['IdUsuario']; ?>"><?php echo $res['Nombre']; ?></option>
<?php } ?>
</select>