Reputation: 1101
I want to ask about javascript alert button.
Is it possible to do anything (e.g: redirect, clear form) after I clicked the OK button on the alert button?
Upvotes: 0
Views: 423
Reputation: 6170
You could change your alert
to use a confirm
window
var response = confirm('Are you sure you want to clear the form?');
if (response){
// clear the form
console.log('clearing the form approved');
}
The confirm
window is similar to the alert
except it shows OK and Cancel buttons. It returns a bool
result depending on the user's choice.
Like the alert
window, it halts program/script execution until the user makes a decision
Upvotes: 1
Reputation: 85545
You can just apply your function right after the alert:
alert('something');//execution is halted until ok button is pressed
foo(); // calls the foo method after ok button is pressed
Upvotes: 2