Reputation: 73
I use ajax to edit directly data in table. I would like to display a confirm box before editing. The user has only to click on a field and then he can edit. If he let blank an alert pops up. Now i would like to display a confirm box after edit is done. This is where i'm stuck. behold my codes.
<tr>
<th cursor:pointer">NomFaculte</th>
<th cursor:pointer">Adresse</th>
</tr>
<?php
while($row=mysqli_fetch_array($resa))
{
?>
<tr class="edit_tr">
<td class="edit_td" id="<?php echo $row['id']; ?>">
<span id="Adresse_<?php echo $row['id']; ?>" class="text"><?php echo
$row['Adresse']; ?></span>
<input type="text" value="<?php echo $row['Adresse']; ?>" class="editbox"
id="Adresse_input_<?php echo $row['id']; ?>"/>
</td>
<td class="edit_td" id="<?php echo $row['id']; ?>">
<span id="NomDroyen_<?php echo $row['id']; ?>" class="text"><?php echo
$row['NomDroyen']; ?></span>
<input type="text" value="<?php echo $row['NomDroyen']; ?>"
class="editbox" id="NomDroyen_input_<?php echo $row['id']; ?>"/>
</td>
$(document).ready(function()
{
$(".edit_td").click(function()
{
document.getElementById('user_insert').style.display="none";
var ID=$(this).attr('id');
$("#Adresse_"+ID).hide();
$("#NomDroyen_"+ID).hide();
$("#Adresse_input_"+ID).show();
$("#NomDroyen_input_"+ID).show();
}).change(function()
{
var ID=$(this).attr('id');
var Ad=$("#Adresse_input_"+ID).val();
var NomD=$("#NomDroyen_input_"+ID).val();
var dataString = 'id='+ ID +'&Adresse='+Ad+'&NomDroyen='+NomD;
if(Ad.length>0&& NomD.length>0)
{
$.ajax({
type: "POST",
url: "faculte_modifier.php",
data: dataString,
cache: false,
success: function(html)
{
$("#Adresse_"+ID).html(Ad);
$("#NomDroyen_"+ID).html(NomD);
$("#NombreEtudiants_"+ID).html(NombEtu);
}
});
}
else
{
alert('Don't let this field empty !.');
}
});
// Edit input box click action
$(".editbox").mouseup(function()
{
return false
});
// Outside click action
$(document).mouseup(function()
{
$(".editbox").hide();
$(".text").show();
document.getElementById('user_insert').style.display="block";
});
});
Upvotes: 0
Views: 72
Reputation: 31
if(confirm('Are you sure?')) {
$.ajax({
type: "POST",
url: "faculte_modifier.php",
data: dataString,
cache: false,
success: function (html)
{
$("#Adresse_" + ID).html(Ad);
$("#NomDroyen_" + ID).html(NomD);
$("#NombreEtudiants_" + ID).html(NombEtu);
}
});
}
Upvotes: 1
Reputation: 20750
You can use confirm() method like following.
if (confirm('Are sure you want to edit')) {
alert('confirmed');
// do your stuff here;
}
Upvotes: 0