0

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());
    }
Frank
  • 39
  • 1
  • 7
  • check this question http://stackoverflow.com/questions/4076770/getting-value-of-select-dropdown-before-change – Ledhund Jun 14 '13 at 14:21

3 Answers3

2

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
}
tymeJV
  • 99,730
  • 13
  • 150
  • 152
1
function updateDb() {

//confirm box
var k = confirm('Are you sure to proceed?');

if(k)
{
    $.post("execute.php", $("#form").serialize());
}else{
    return;
}
}
Sundar
  • 4,318
  • 6
  • 32
  • 56
1

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;
        }
    });
});
fusion27
  • 1,778
  • 20
  • 24