Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run another javascript when user clicks "ok" on alertbox

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,

     });
 }
like image 441
user1323294 Avatar asked May 23 '12 07:05

user1323294


People also ask

How do I handle alert OK button?

To click on the Ok button on alert, first of all we have to switch to alert with switchTo(). alert() method. Next, to click on the Ok button, we have to use accept() method. Please note we cannot identify elements on alert by inspecting on them.

Does JavaScript alert stop execution?

One of the nice things about the built-in JavaScript alert is that - unlike virtually anything else in JavaScript - it's synchronous. It's completely blocking, and no other code will execute until it's been dismissed.

What is the alternative of alert in JS?

blurt is a javascript replacement for default alert(), prompt(), and confirm() functions in javascript. The equivalents in blurt are: alert() -> blurt() prompt() -> brompt()


1 Answers

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();
like image 123
Jamie Dixon Avatar answered Nov 03 '22 10:11

Jamie Dixon