0
I need to get the id of an item on my list and fill in the input with this id. So far with some searches I was able to choose which of the options and display the id in an Alert, but I need to fill the tcod input with the id value, I tried with attr and prop but no result. Could you help me ?
$(".tt").click(function() {
var valor = $(this).parent().parent().find('.tes');
alert(valor.html());
}
<label>Codigo<span style="color:red">*</span></label>
<input class="form-control" type="number" name="tcod" required>
<?php
$nome = $_POST['nome'];
$sql = "SELECT * FROM `cad` WHERE nome LIKE '%$nome%' ";
$ex = mysqli_query($conn, $sql);
while($rows = $ex->fetch_array()){
echo "<tr>";
echo "<td class='tes'>".$rows['idcad']." </td>";
echo "<td>".$rows['nome']." </td>";
echo "<td>".$rows['nome_mae']." </td>";
echo "<td>".$rows['idade']." </td>";
echo "<nav id='edita'>";
echo "<td><i class='fa fa-search tt' id='cod' value=''></i></td>";
echo "</nav>";
echo "</tr>";
}
}
?>
Vc changes the value of an input with
.val()
. You cannot repeat id’s in HTML (id='cod'
) and why there is a</nav>
in the middle of the table?– Sam
Nav was one of the tests I did, because in the first attempts I was launching the value inside the input but only the last option, can be removed from the code, but I tried to put it like this : <script type="text/javascript"> $(".tt"). click(Function() { var value = $(this).Parent().Parent().find('.tes'); $("input[name='tcod']").val(value); }); </script>
– Leonardo Silveira