Refresh the page after click OK on alert box - javascript

In checkout page of my magento store, I need to clear some inputs when an alert box is showed and user press OK. Is possible to do that?
I have no control over the javascript alert. So I think in a script that detect an alert with a specific message and clear inputs when button of that alert is clicked.
UPDATE
Fixed!
file: opcheckout.js
line: 888
I add location.reload(); because document.location.reload(true); not work on IE. Thanks everybody!

Probably try overriding default alert and write a custom function like below,
var c_alert = alert;
window.alert = function (str) { //override default alert
c_alert(str + ' my message');
location.reload();
//or write code to clear input fields here
}
//below seems to be triggered from somewhere where you don't have control.
alert('test');

Javascript
if(confirm('your confirmation text')){
document.location.reload(true);
}

Make it refresh after the alert. The javascript code shouldn't execute before the alert is gone

Related

How to clear the text of asp:TextBox when user again open the pop up window?

I follow How to clear a textbox using javascript but my scenario is little change. I have a login button and when user click on login a pop-up window is open. He fill the textbox and for some reason he go back to main page. When he again come to login popup window he previous value is not cleared. May be this is because the page is not loaded. And I do not want to load page again. I want to use JQuery/JavaScript to remove the entered text. I has idea that I write code inside Close button but I don't know how to clear the textboxes. Please help.
Here is the code, scenario is that I used popup for login and sign up. In login popup there is link "Don't have login Id" when user click on it the sign up pop up with form is open.
Don't have Login Id
And the JavaScript method is
<script type="text/javascript">
function function_deletePreviousData(){
document.getElementById("signUp").value = "";
}
</script>
But nothing happened. I think this is because I don't give element id, I just give id of element which I used to land on sign up pop up form. Any idea for clear all form without accessing all elements and give it null value.
Instead of including code in close button click event, we should write code in login button click.This is one of my suggestion.
Try this once:
Javascript:
<script type="text/javascript">
function LoginButtonClick() {
document.getElementById`("TextBox_Id").value = "";
}
</script>
JQuery:
jQuery("#LoginButton_Id").Click( function()
{
$('#TextBox_Id').val("");
} );
Finally I find the method in JQuery to reset all fields. Just Trigger reset.
$('#form').trigger("reset");
Thanks all for help.

multipule actions if statement in javascript

I want to create a multipule action if statement, for example this is my script now:
if (document.getElementById("username").value==null || document.getElementById("username").value=="")
{
alert("username must be filled out");
return false;
}
and I want that in the same time as the alert pops up to add another action like change to path to some image or something llike that..
anyone know how to do this?
thanks,
Lian
The alert popup in browsers is a kind of modal form.
From the moment you call the alert, user interaction with the browser is limited to the popup buttons and you cannot do anything else.
You can't offer the user "multiple actions" with an alert popup.
Try creating your own modal box as your message box.
because once you pop up an alert in js the code below will not executed unless you hit the ok button

window.open in phonegap

I am new to phonegap. I am using phonegap with IOS. the problem i am facing is, JS function window.open('URL') is not working. it gives nothing. can anyone help me what is actually going on?
Thanks
To show the confirmation box you need to do some thing like this
//process the confirmation dialog result
function onConfirm(button) {
alert('You selected button ' + button);
}
// Show a custom confirmation dialog
//
function showConfirm() {
navigator.notification.confirm(
'You are the winner!', // message
onConfirm, // callback to invoke with index of button pressed
'Game Over', // title
'Restart,Exit' // buttonLabels
);
}
Just invoke the showConfirm() on click of a button...
try this:window.location ='http://www.google.com';
window.location.href ='http://www.google.com';
I used simple page with pop transition because jquery dialog is also works as a page but it effects your css, thats why i use a simple page with pop transition. and it appends in the current DOM due to which i have all of access to previous page form. just like openr in case of Window.open()
problem solved

Firefox submitting form even in the case of alerts

We have a requirement that if a user clicks on any link, he should not be able to click on any other link.to achieve this, we have written a java script with incrementing counter.In case , if a user has already clicked on any link we are showing a alert box with some message.On IE its working fine, In Firefox , I am getting the alert for second click but firefox does not stop the processing of first request and refreshes the page even if alert box is untouched.
We are submitting the forms through explicit java scripts.
Hi All PFB the snippets
<script>
var counter = 0;
function incrementCount(){
if(counter>0){
alert('Your request already in progress. Please wait.');
return false;
}else{
counter=counter+1;
return true;
}
}
</script>
Form submission script:
<script>
function fnTest() {
if(incrementCount()){
document.FormName.method = "POST";
document.FormName.action = "SomeURL";
document.FormName.submit();
}else{
return false;
}
}
</script>
Link through which we are submitting the form
<span>Test</span>
Your question is unclear. If a user clicks on a submit button he should not be able to click a link? You'll need to post your code.
With regards to the form post my guess is you didn't return false onsubmit
"On IE its working fine, In Firefox ,
I am getting the alert for second
click but firefox does not stop the
processing of first request and
refreshes the page even if alert box
is untouched"
Well, what's wrong. Firefox is submitting the first request as you want and it shows an alert on the second click. How is IE different? Is FF doing a double submit?
PS: You dont really need to use a counter. Use this code :
var handlers = {
alert : function(){
alert('Your request is already in progress. Please wait.')
return false
},
submitForm : function(){
this.onclick = handlers.alert //this refers to the a tag
document.FormName.submit()
}
}
document.getElementById('mysubmitlink').onclick = handlers.submitForm
And on your link becomes:
`<span>Test</span>`
You can allways return false on your onsubmit call.

Yes/No box in Javascript like this one here in StackOverflow?

I want to know how can I display a confirmation box when the users try to get out of the page, like this one here in StackOverflow when you try to close the "Ask Question" page.
Thanks you in advance.
Actually, all that is necessary is this:
window.onbeforeunload = function(){ return "You should save your stuff."; }
This is also kind of a dupe of this: How to show the "Are you sure you want to navigate away from this page?" when changes committed?
In javascript, attach a function to window.onbeforeunload, like so:
window.unbeforeunload = function (e)
{
// return (prompt ('Are you sure you want to exit?'));
// EDIT: Amended version below:
var e = e || window.event;
if (e) e.returnValue = 'Your exit prompt';
return 'Your exit prompt';
}
EDIT:
As the comments below indicate, I had misunderstood the working of the event. It should now work as intended.
Ref: window.onbeforeunload (MDC)
probably a dupe: How do you prevent a webpage from navigating away in JavaScript?, but you can do this by adding an delegate to the window.onbeforeunload event
<script type="text/javascript">
window.onbeforeunload = function() {
//will show a dialog asking the user if
//they want to navigate away from the current page
// ok will cause the navigation to continue,
// cancel will cause the user to remain on the current page
return "Use this text to direct the user to take action.";
}
</script>
Update: doh! updated code to do what the OP really wanted :D
You want to catch the onbeforeunload event of window. Then if you return a string, the browser will display your message in a prompt. Here's an article with sample code.
You can use the window.onbeforeunload event to catch this. If there is any value inside the textarea then an alert message is shown.
That's browser based.
As long as you implement <form> tag, and you type in something in the form, and in Google Chrome, it will prompt you that message.

Categories

Resources