deselect the alert in javascript - javascript

I am working on some project and I have used alert type function in my project.
I want to do a task is that if I cross or cancel the alert box then i don't want to continue the task
<td><input type="submit" Onclick="myfunction()" value="Delete"> <input type="reset" value="Reset"></td>
<script>
function myfunction() {
alert("You are trying to delete faculty record permanently");
}
</script>
In above code if i cancel the alert box then i want to return on previous page and if I click on OK on alert box then i want to perform task successfully
can anyone suggest me that how can i do this task??

alert() is for displaying a message. If you want to confirm something, you can use the aptly named confirm():
if(confirm("Should we do it?")) {
alert("We did it!");
} else {
alert("Or not.");
}
You will also probably want to attach this handler to the onsubmit event of the form. In fact, simply setting onsubmit="confirm('…')" will work; the return values match up.

alert will just alert text (message) to the user, it doesn't expect any input or interactions.
confirm on the other hand will check if the user want to proceed or cancel by letting the user choose between two buttons.
prompt will prompt the user to enter some text and then return it so it can be used.
Example:
In your case you need to use confirm like this:
var result = confirm("You want to continue?"); // confirm will return either true or false
if(result)
alert("Let's continue then!");
else
alert("Bye!");

You cannot do this with Window.alert() as it returns undefined. See https://developer.mozilla.org/en-US/docs/Web/API/Window/alert
I think what you're looking for is Window.confirm(). This returns a boolean depending on what button (typically "OK" or "Cancel") you clicked. See https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm
result = confirm('You are trying to delete faculty record permanently')
if (result) {
alert('Delete record')
} else {
alert('Do not delete record')
}

Related

Javascript - Confirm box to redirect user when they click on exit button

My objective is to when the user clicks on the exit button, it should appear a box with 2 buttons, to confirm or cancel the leave. After the confirm button is clicked, a redirect is needed.
I tried a lot of solutions, but I could only find a solution that I can control what happens after the confirm button.
But I need to do some action after they click on the confirm
My code:
window.onbeforeunload = function () {
return "message"
}
That opens a box to confirm the exit, but I can't control the actions after it
something like this
const result = confirm('Do this?');
if(result){
//redirect here
}

How to create a confirm alert box?

I have a button. When I click on the button, the alert box should be visible.
The alert box will have two buttons, Yes and Cancel
If I click on Cancel button, the alert box should be closed.
When I click on Yes button, It will take me to another php page.
How can I achieve this?
Wait I understood. Here are two examples for you I'm explaining.
<button onClick="delete()"> goTo </button>
<script>
function goTo ()
{
var x = confirm('Are you ready to go this site');
if( x === true )
{
open('https://www.fiverr.com/dev_sal');
}
else
{
document.write('sorry, to hear it!');
}
}
</script>
if you don't need else condition So, put off. merely use if condition.
Cheer you Be happy if made some mistake to tell me, please?

Javascript confirm box not able to submit form on selecting yes

In jsp , clicking on button called sumbitForm() function as below
document.Data.formSubmit.value="Yes";
document.Data.action.value='SUMBIT';
document.Data.submit();
here giving proper result and setting value as occured on controller
In same JSP, calling onload function ,In that checking if command class variable set = occured then only confirmation box can show and after clicking yes button of confirmation box then request should process.. I used document.Data.submit() but its not working and not giving exception.
i think this will help you
if(confirm("Are you sure you want to submit the form ") == true ){
// then submit the form
}

Javascript alert button OK button

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?
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
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

How do I add an onclick event to the OK button of the Javascript confirm box?

I am working with a .Net 1.1 web application. There is a Save button that, when clicked, will pop up the Javascript confirm box. Once the user clicks OK a long running process is kicked off. We would like to show a busy indicator when the user clicks the OK button of the confirm dialog. Can this be done?
if(confirm("Are you sure you would like to save?")){
alert("Loading") //Replace with what you want to do
}
The button on an alert() dialog is not scriptable. You need to find where in the code the alert() is called and patch in to the code just after this.
What you want to do is pretty simple. A confirm('Text') returns true or false after the user makes their selection. All you need to do is on true show a busy indication.
Here is what you're looking for http://jsfiddle.net/Akkuma/C6ZZf/
$('#save').on('click', function () {
var shouldSave = confirm('Make your choice');
if(shouldSave) {
alert('Do saving');
}
else {
alert('Not saving');
}
});

Categories

Resources