Run another javascript when user clicks "ok" on alertbox
alert, function, javascript, jquery
Solution
The `alert` function halts execution of the code until it's dismissed. This means that any code you want to run after the alert has been clickd can simply be placed after the call to the `alert` method.
alert("New data!");
UpdateDB();
Problem
Basically I have a script that checks database every 10 seconds and notifys user if data has changed with a javascript alert box. But I need the database also to be changed when user has seen the alert and clicked OK. So is it possible to make a javascript function run when user clicks "OK" on javascript alert? So for example ``` <html> <head> <script type="text/javascript"> function show_alert() { alert("New data!"); } </script> </head> <body> <input type="button" onclick="show_alert()" value="Show alert box" /> </body> </html> ``` And when user clicks OK it should run this function ``` function UpdateDB() { jQuery.ajax({ type: "POST", url: "update.php", data: 'condition=ok', cache: false, }); } ```