I have a table that contains a column of dates that can be changed through the datepicker .
<td>
<div class="input-group date" data-provide="datepicker">
<input type="text" class="form-control" name="dataPrevisao" id="dataPrevisao" rel="<?php echo odbc_result($resultado,"stamp");?>" value="<?php echo odbc_result($resultado,"dvalor");?>" />
<div class="input-group-addon">
<span class="glyphicon glyphicon-calendar small"></span>
</div>
</div>
What i want to do, is after the change of date, the register is automatically updated in the table. For that, i have a php file - changePrevisao.php:
<?php include("includes/odbc.ini");
$iniciais=str_replace(' ', '', $_SESSION['iniciais']);
$stamp=$_POST['stamp'];
$dataP=$_POST['dataP'];
$query = " update od set marcada=1, data='$dataP', usrdata=convert(varchar(10),getdate(),112),
usrhora=right(convert(varchar(19),getdate(),121),8), usrinis='$iniciais' where od.odstamp='$stamp'";
odbc_exec($sqlconnect,$query);
?>
I have problems in building the user function to ajax that allows pass the data to the php file , does anyone can help me ?
After searching and testing , I created the following function:
<script>
$(document).ready(function(){
$(document).on('change', '#dataPrevisao', function () {
var stamp = $(this).attr('rel');
var dataP = $(this).val();
var dataString = 'stamp='+ stamp +'&dataP='+ dataP;
$.ajax({
type: "POST",
url: "changePrevisao.php",
data: dataString,
cache: false,
success: function(new_data){
$(stamp).html(new_data);
$(stamp).dialog();
alert('Load was performed.');
}
});
});
});
</script>
Now i can update the date in the db, but the result is not as i expected, the change only occurs when I change directely the input and not through the datepicker. What do I need to change in the function so that it takes into account the changes made by the datepicker ?