So i got this select box and onchanging it updates an database with the selected value. What i would like is when i change the value a confirm box pops up. If you press cancel the change wont happen if you press yes you change it is this possible?
Thank you for looking at it.
echo "<select id='select' name='select' onChange='updateDb()'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['phonenr'] . "'>" . $row['phonenr'] . "</option>";
}
echo "</select>";
function updateDb() {
$.post("execute.php", $("#form").serialize());
}
You can do:
if (confirm('Are you sure you want to save this thing into the database?')) {
// Save it!
$.post("execute.php", $("#form").serialize());
} else {
//Nada
}
function updateDb() {
//confirm box
var k = confirm('Are you sure to proceed?');
if(k)
{
$.post("execute.php", $("#form").serialize());
}else{
return;
}
}
Expanding on answer from @tymeJV
$(document).ready(function() {
$('#select').on('change',function(){
var k = confirm('Are you sure to proceed?');
if(k) {
$.post("execute.php", $("#form").serialize());
}else{
return false;
}
});
});