I want to update a field in db as 1 or 0 when i click on yes or no button..
<table id="main" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Date</th>
<th>Amount</th>
<th>Approve</th>
</tr>
</thead>
<tbody>
<?php $i = 0; foreach($purchaseorder as $tdata): $i++; ?>
<tr>
<td><?php echo $tdata['pay_date']; ?></td>
<td><?php echo $tdata['amount']; ?></td>
<td>
<input type="button" onClick="save(this);" value="Yes">
<input type="button" onClick="save(this);" value="No">
</td>
</tr>
<?php endforeach; ?>
<script>
function save(){
$.ajax({
type: "POST",
url: "Marketing/add.ctp",
data: {title: title},
success: function(data) {
alert("Ajax save executed!");
}
});
}
</script>
</tbody>
</table>
Above code displays the button in view page as yes and no. When i click on yes button there is no change in database. What should i do??
Take the value of the button and send it through AJAX request like this.
<table id="main" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Date</th>
<th>Amount</th>
<th>Approve</th>
</tr>
</thead>
<tbody>
<?php $i= 0;
foreach($purchaseorder as $tdata): $i++; ?>
<tr >
<td><?php echo $tdata['pay_date']; ?></td>
<td><?php echo $tdata['amount']; ?></td>
<td> <input type="button" onClick="save(this);" value="Yes">
<input type="button" onClick="save(this);" value="No"></td>
</tr>
<?php
endforeach;
?>
</tbody>
</table>
<script>
function save(curEle){
$.ajax({
type: "POST",
url: "Marketing/add.ctp",
data: {status: curEle.value},
success: function(data) {
alert("Ajax save executed!");
}
});
}
</script>
In your PHP script save the status as 1 for 'yes' and 0 for 'no'