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?
Related
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')
}
I have created a form where user can create his profile, now I want that if user do not click on save/submit button on the page and clicks on any other available link other than save.
Then he should get confirm popup of JavaScript mentioning that you are aborting the creation of profile. I am unable to find any event via which I can achieve this.
Other links are navigation links available on my page.
If you are using button for submit and others as a link then you can find out like this:
$(document).ready(function() {
$(document).('on','click',function(){
var pressedButton = $(this).text();
if(pressedButon == "Submit" || pressedButton =="Save")
{
return false;
}
else
{
$("a").on('click',function() {
var confirmAns = confirm('Your message');
if(confirmAns == true)
{
// DO whatever you want...
}
else
{
//Do whatever you want...
}
});
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
You can use onblur event for it and you can achieve your goal. So when a user click anywhere in your web page then the onblur event automatically fire.
You should use onblur event on your save/submit button.
<button onblur="myFunction()" type="button">Save</button>
<script>
function myFunction() {
var txt;
var r = confirm("You are aborting the creation of profile");
if (r == true) {
return true;
} else {
return false;
}
}
</script>
Try using some plugin. There is one jQuery plugin "Are You Sure"
So you just need below code snippet
$('form').areYouSure();
// OR
$('form.my_form_class').areYouSure();
There are some advanced option available with plugin. Checkout its documentation.
If I understood right, you want this two possibilities:
1.User clicks submit button: form gets submitted
2.User clicks "a" link: get alert asking for confirmation to leave the registration process.
First point will be done automatically as it's a form submit button without the need of extra jQuery.
Second point would just need the following code in order to show the confirmation button:
<script>
$(document).ready(function(){
$('a').on('click',function(e){
if (!confirm("Are you sure you want to exit the registration process?")){
e.preventDefault();
return false;
}
});
});
</script>
I'm looking for a script that will fire up whenever I click on an input box there will be a pop up modal with TextField and save and cancel button. So when I click save the text i typed on the text field will be saved on the input box.
I'm so sorry been busy with something else and I'm so sorry for being not so descriptive with my question (just a newbie). I'm currently using this: mywebdeveloperblog.com/my-jquery-plugins/jquery-popbox my only problem is that there's no 'cancel' button so there's no way to cancel in iOS or other touch devices. Can anyone help? Thanks.
Search for jquery ('#seuID').onclick() function with a alert inside the function it will call and pass the result into a variable or array so you can do what you want with it.
Try
$('input[type="text"]').focus(function(){
//your code here
});
you can find more info here.
$(document)
.ready(function () {
$('input')
.click(
function () {
var NWin = window.open($(this)
.prop('href'), '', 'height=800,width=800');
if (window.focus) {
NWin.focus();
}
return false;
})
});
I have a search form (you can see the form here) that uses some javascript to check that at least one field has been completed before allowing a search to take place.
I'm not great with Javascript so please bear with me. I've managed to get the validation working (with the help of brilliant Stack Overflow users), and get the submit button to be re-enabled once the form has passed validation using the following code:
$(function(){
$('#detailed-search-form').on('submit',function(e){
e.preventDefault();
var oneFilled = checkFields($(this));
if(oneFilled) {
$(this).unbind('submit').submit()
} else {
overlay();
}
});
});
The trouble is that the first click on the submit button doesn't actually submit the form, it simply enables the button. This the needs another click before the form is submitted.
Hopefully there's a way I can get the form to not only re-enable the button when it's clicked, but also submit the form without the need for a second click?
Any help will be greatly appreciated!
Thanks in advance,
Tom
The submit handler you wrote should basically say "hey, if you didn't provide at least one field, I'll prompt you a nice green overlay, otherwise let's move on with the search" - no need to unbind anything.
$(function(){
$('#detailed-search-form').on('submit',function(e){
if( !checkFields($(this)) ) {
// if the form isn't valid, show overlay
overlay();
return false;
} else {
// else just continue with form action
return true;
}
});
});
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');
}
});