is working my selection a value of colum of the table and now is not working now is say undifined
<?php foreach ($servicos->getservicosempresa($d)as $r): ?>
<tr>
<!--tr-->
<?php
if($r['quantidade']==0){
?>
<td style="visibility:collapse" > <?php echo $r['id']; ?></td>
<td style="background-color:#CC0000"><?php echo $r['nome']; ?>
</td>
<td style="background-color:#CC0000"><?php echo $r['descricao']; ?>
</td>
<td style="background-color:#CC0000"><?php echo $r['quantidade']; ?>
</td>
<td style="background-color:#CC0000"><?php echo $r['precosiva']; ?></td>
<td style="background-color:#CC0000"><?php echo $r['taxa']; ?></td>
<td style="background-color:#CC0000"><?php echo $r['txt']; ?>
</td>
<td style="background-color:#CC0000"><?php echo $r['valordesc']; ?>
</td>
<td style="background-color:#CC0000"><?php echo $r['valoriva']; ?>
</td>
<td style="background-color:#CC0000"><?php echo $r['precototal']; ?>
</td>
<td style="visibility:hidden"> <button type="submit" class="btn">
<span class="glyphicon glyphicon-pencil"></span> Selecionar
</button>
</td>
</tr>
<?php
} else if($r['quantidade']<=5 & $r['quantidade']>0){?>
<td data-nome="<?php echo $r['id']; ?>" style="visibility:collapse"><?php echo $r['id'];?> <input type="text" value="<?php echo $r['id'];?>" style="visibility:hidden;width: 5px" name="id" id="id"></td>
<td style="background-color:#F5E79E"><?php echo $r['nome']; ?>
</td>
<td style="background-color:#F5E79E"><?php echo $r['descricao']; ?>
</td>
<td style="background-color:#F5E79E"><?php echo $r['quantidade']; ?>
</td>
<td style="background-color:#F5E79E"><?php echo $r['precosiva']; ?></td>
<td style="background-color:#F5E79E"><?php echo $r['taxa']; ?></td>
<td style="background-color:#F5E79E"><?php echo $r['txt']; ?>
</td>
<td style="background-color:#F5E79E"><?php echo $r['valordesc']; ?>
</td>
<td style="background-color:#F5E79E"><?php echo $r['valoriva']; ?>
</td>
<td style="background-color:#F5E79E"><?php echo $r['precototal']; ?>
</td>
<td> <button type="submit" class="btn">
<span class="glyphicon glyphicon-pencil"></span> Selecionar
</button>
</td>
</tr>
<?php
}
else {?>
<td style="visibility:collapse"><?php echo $r['id']; ?><input name="id" id="id" style="visibility:hidden;width: 5px" class="form-horizontal" type="text"></td>
<td ><?php echo $r['nome']; ?>
</td>
<td><?php echo $r['descricao']; ?>
</td>
<td><?php echo $r['quantidade']; ?>
</td>
<td><?php echo $r['precosiva']; ?></td>
<td><?php echo $r['taxa']; ?></td>
<td><?php echo $r['txt']; ?>
</td>
<td><?php echo $r['valordesc']; ?>
</td>
<td><?php echo $r['valoriva']; ?>
</td>
<td><?php echo $r['precototal']; ?>
</td>
<td> <button type="submit" class="btn">
<span class="glyphicon glyphicon-pencil"></span> Selecionar
</button>
</td>
<?php }
?>
</tr>
<?php endforeach; ?>
</tbody>
<script>
$(function(){
$(document).on('click', '.btn', function(e) {
e.preventDefault;
var nome = $(this).parent().parent().find('td').data('nome');
$("input[name='id']").val(nome);
alert(nome);
});
});
</script>
problem solve
my mistake
i forget put this in td data-nome="<?php echo $r['id'];?>"