I'm having a hard time submitting a specific field in the case of <select>
with 3 <option>
. When I get the field to insert some data into the database, it does not have the value, but rather the Undefined or Object information (From what I understand it brings the Undefined or Object data) In the form that the code is, it is not imputing data. Here is the code below:
function updatedata(str){
var id = str;
var nm = $('#nm'+str).val();
var gd = $('#gd'+str).val();
var pn = $('#pn'+str).val();
var al = $('#al'+str).val();
var nt = $('#nt'+str).val();
var nq = $('#nq'+str).val();
var me = $('#me'+str).val();
var sc = $('#sc option:select'+str).text();
var nr = $('#nr'+str).val();
var ob = $('#ob'+str).val();
var datas="nm="+nm+"&gd="+gd+"&pn="+pn+"&al="+al+"&nt="+nt+"&nq="+nq+"&me="+me+"&sc="+sc+"&nr="+nr+"&ob="+ob;
$.ajax({
type: "POST",
url: "php/updatedata.php?id="+id,
data: datas
}).done(function( data ) {
$('#info').html(data);
viewdata();
});
}
The input text fields work perfectly, but only the select box that is not functional. Follow the select in html.
<div class="form-group">
<label for="sc">status:</label>
<select class="form-control" id="sc" >
<option value='1'>Sim</option>
<option value='2'>Não</option>
<option value='3'>Revisar</option>
</select>
I had already put the html values as text instead of numbers, but there was no input either.
Complementing this information is passed to an Update set via modal, if I change any field within the modal the input is performed but only the value of <select>
that is not inputted.
Thank you in advance!
Well, I was able to input the data with the answer.
var sc = $('select option:selected').text();
But a problem occurred that it replicates the information of the according to the number of lines of the bank, for example:
If the bank has 5 records it will add SimSimSimSimSim and not only Yes and if I update the information with a No it will do NaoSimSimSimSim.
If you can help me, I will post the complete code with html and php, I do not know what to do to solve this problem anymore.
Thank you.
<script>
function viewdata(){
$.ajax({
type: "GET",
url: "php/getdata.php"
}).done(function( data ) {
$('#viewdata').html(data);
});
}
$('#save').click(function(){
var nm = $('#nm').val();
var gd = $('#gd').val();
var pn = $('#pn').val();
var al = $('#al').val();
var nt = $('#nt').val();
var nq = $('#nq').val();
var me = $('#me').val();
var sc = $('#sc').val();
var nr = $('#nr').val();
var ob = $('#ob').val();
var datas="nm="+nm+"&gd="+gd+"&pn="+pn+"&al="+al+"&nt="+nt+"&nq="+nq+"&me="+me+"&sc="+sc+"&nr="+nr+"&ob="+ob;
$.ajax({
type: "POST",
url: "php/newdata.php",
data: datas
}).done(function( data ) {
$('#info').html(data);
viewdata();
});
});
function updatedata(str){
var id = str;
var nm = $('#nm'+str).val();
var gd = $('#gd'+str).val();
var pn = $('#pn'+str).val();
var al = $('#al'+str).val();
var nt = $('#nt'+str).val();
var nq = $('#nq'+str).val();
var me = $('#me'+str).val();
var sc = $('select option:selected').text();
var nr = $('#nr'+str).val();
var ob = $('#ob'+str).val();
var datas="nm="+nm+"&gd="+gd+"&pn="+pn+"&al="+al+"&nt="+nt+"&nq="+nq+"&me="+me+"&sc="+sc+"&nr="+nr+"&ob="+ob;
$.ajax({
type: "POST",
url: "php/updatedata.php?id="+id,
data: datas
}).done(function( data ) {
$('#info').html(data);
viewdata();
});
}
function deletedata(str){
var id = str;
$.ajax({
type: "GET",
url: "php/deletedata.php?id="+id
}).done(function( data ) {
$('#info').html(data);
viewdata();
});
}
</script>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>ID</th>
<th>Contrato</th>
<th>Carteira</th>
<th>Data Pagamento</th>
<th>Valor Pagamento</th>
<th>Parcelamento</th>
<th>Quitação</th>
<th>Envio</th>
<th>Status</th>
<th>Recuperador</th>
<th>Observação</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $row['id_acordo']; ?></td>
<td><?php echo $row['ncontrato']; ?></td>
<td><?php echo $row['ncarteira']; ?></td>
<td><?php echo $row['dpagamento']; ?></td>
<td><?php echo $row['vpagamento']; ?></td>
<td><?php echo $row['nparcelamento']; ?></td>
<td><?php echo $row['nquitacao']; ?></td>
<td><?php echo $row['menvio']; ?></td>
<td><?php echo $row['scadastro']; ?></td>
<td><?php echo $row['nrecuperador']; ?></td>
<td><?php echo $row['observacao']; ?></td>
<td>
<a class="btn btn-warning btn-sm" data-toggle="modal" data-target="#myModal<?php echo $row['id_acordo']; ?>"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a>
<a class="btn btn-danger btn-sm" onclick="deletedata('<?php echo $row['id_acordo']; ?>')" ><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
<!-- Modal -->
<div class="modal fade" id="myModal<?php echo $row['id_acordo']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel<?php echo $row['id_acordo']; ?>" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel<?php echo $row['id_acordo']; ?>">Editar Linha</h4>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<p id="nm<?php echo $row['id_acordo']; ?>">
<b>Contrato: </b><?php echo $row['ncontrato']; ?>
</p>
</div>
<div class="form-group">
<p id="gd<?php echo $row['id_acordo']; ?>">
<b>Carteira: </b><?php echo $row['ncarteira']; ?>
</p>
</div>
<div class="form-group">
<p id="pn<?php echo $row['id_acordo']; ?>">
<b>Data: </b><?php echo $row['dpagamento']; ?>
</p>
</div>
<div class="form-group">
<p id="al<?php echo $row['id_acordo']; ?>">
<b>Valor: </b><?php echo $row['vpagamento']; ?>
</p>
</div>
<div class="form-group">
<p id="nt<?php echo $row['id_acordo']; ?>">
<b>Parcelamento: </b><?php echo $row['nparcelamento']; ?>
</p>
</div>
<div class="form-group">
<p id="nq<?php echo $row['id_acordo']; ?>">
<b>Quitação: </b><?php echo $row['nquitacao']; ?>
</p>
</div>
<div class="form-group">
<p id="me<?php echo $row['id_acordo']; ?>">
<b>Envio: </b><?php echo $row['menvio']; ?>
</p>
</div>
<div class="form-group">
<p id="nr<?php echo $row['id_acordo']; ?>">
<b>Recuperador: </b><?php echo $row['nrecuperador']; ?>
</p>
</div>
<div class="form-group">
<label for="sc">status:</label>
<select class="form-control" id="sc">
<option>Sim</option>
<option>Nao</option>
<option>Revisar</option>
</select>
</div>
<div class="form-group">
<label for="ob">Observação:</label>
<input type="text" class="form-control" id="ob<?php echo $row['id_acordo']; ?>" value="<?php echo $row['observacao']; ?>">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
<button type="button" onclick="updatedata('<?php echo $row['id_acordo']; ?>')" class="btn btn-primary">Salvar</button>
</div>
</div>
</div>
</div>
</form>
</td>
</tr>
<?php
}
?>
</tbody>
</table>