alert and confirm boxes do not appear - javascript

I have a couple of webpages which i in part build up dynamically (php and JavaScript).
Everything used to work well in the past, but now the various calls to alert and confirm do not cause dialog boxes to appear anymore.
Using the JavaScript debugger in firefox i can verify, for example, that the statement
var r = confirm("Do you really want to save this data?");
is executed, but no dialog window is opened, and the code goes on as if i had pressed "no" (in this step the watch expression for r changes from "undefined" to "false").
The same happens for calls to alert - the code is executed, but no dialog window is shown.
I have not checked these pages in a while, which means there have been various software updates since then.
Strangely however, this seems not to be a browser-wide effect: a different set of similarly built pages does not show this behavior - there, the dialog boxes are shown.
Is it possible that there is some setting in JavaScript or php which prevents dialogs from opening?
Does anybody have an idea how to fix this problem?

I had the same problem before and my problem was solved with the following code. You try it too, maybe it will help you too.
let r = window.confirm("Do you really want to save this data?");

Related

focus() method doesn't work while manually focusing with the mouse or tab key does

I try to focus an element of an email field in this webpage, with the following code:
document.querySelector("#user_email").focus();
While manual focusing with either clicking on the field with the mouse or using tab works, the focus() method fails to create the focus, as it seems both from the fact the CSS doesn't change, and the console returns "undefined".
As a newcomer, I ask why?
When you're calling focus() from console, focusing won't happen immediately - you have to go back to the site (close console). When you go back from console to a website by clicking on a website, focusing won't happen. Close console using shortcuts or use setTimeout to delay focusing to give you time to go back to the website.
Digital Ocean's input boxes are focusing fine for me. The undefined basically means that nothing is returned from your expression. For example if you type var a = 123 it'll still say undefined. Also there is no special CSS styling on these input boxes. You might be getting confused with the ones in their control panel.
UPDATE: OP was getting confused with Chromes default input styling.
You should try with document.getElementById('user_email').
document.getElementById('user_email').focus() ;
<input id="user_email">

Is there a default focus and select behaviour following a JavaScript alert being clicked?

As per the title, is there a default focus and select behaviour following a JavaScript alert being clicked?
The reason I ask is that I have a JavaScript function validating an asp.net text box in a web forms application. I added a JavaScript alert to the function to help with debugging and the behaviour seemed to change. When I clicked on the OK button of the alert it then set the focus to the field I was validating and selected the text.
I thought it must be something in my code causing this behaviour so I commented out all the instances where I was setting focus and select, but still saw the same behaviour. As soon as I removed the alert it went back to behaving as expected and no longer selected the data in the text box.
Does this sound like it could be related to the JavaScript alert or just something odd going on in my code?
There is auto focus in html5, but the issue here seems like different. If the alert is a custom alert functionality try to remove that and add window.alert() function instead. These are wild guesses, it would e great if you can post your code block here?

stop the flow of program like window.showModalDialog using javascript

We have a big enterprise application that use window.showModalDialog to display modal windows.
We used them at lots of places to show dialog messages and child forms. Now we want to support all the browsers, because in Chrome window.showModalDialog does not display modal dialog, we are thinking of using overlays div over the content and then display top window with div using higher z-index. It works beautifully, But following is the big problem we are facing -
1. Most of code use the following syntax -
var return = window.showModalDialog();
doSomethingWithReturnValue(return);
method to display modalDialog, now the code will not execute and wait for user to close the window the then the next line of code doSomethingWithReturn() method will execute, This code in used at atleast hundards of places in the code. There there is way in javascript to replace window.showModalDialog() with something like follows -
var return = showDialogWindow() // this will use overlays and div with higher index to // display the content
Our problem is that showDialogWindow() will return immediately and all the code will execute without waiting for user to close the window. Alternative will be to use callback, but then results will be to change the whole code around and more testing and potential for more bugs.
Is there way design showDialogWindow() in such a way that showDialogWidnow will wait as long as user have not close the top div.
Thanks,
If you have more questions please let me know.

JQuery / Javascript popup box and form submission creation

I have a jquery/javascript question. For a site I am working on in PHP/JQuery I have the need to create a dialogue box with an ok/cancel button and a message and then submit a form based on if the user says ok or not. I know in javascript I can create a new window that links to a styled page and then I can do a select for if the user hits the ok button and submit the windows parent form using that but the last time I coded something similar to it I felt like it took a lot of lines of code and was wondering if JQuery supported dialogue box creation and if I could do some similar functionality using it (with hopefully less lines of code since everytime I use jquery instead of standard javascript it seems like it really reduces my codebase). If anyone knows of a resource to learn how to do this I would appreciate a link or a second of your time for some pointers.
Thanks!
I think you are looking for something along the lines of the jquery ui dialog.

How to track down a page reload in javascript

I am debugging a page that has a jquery dialog that contains a textbox and an ok button.
When a user hits enter, the page is reloading and the textbox ID & value are being passed to the page reload as get parameters. e.g.
http://example.com?tex_box_id=text_entered_in_text_box
I cannot figure out what is causing this behavior and can't figure out how to best track it down since the page itself is reloading.
I have tried stepping through all the jquery code, but did not have any luck. I can only assume that somebody somewhere attached a key press listener, but I can't figure out who. I know I can work around this by preventing theirs from running, but I still really want to figure out why it is happening.
Note that this does NOT happen if you click the OK button, only if you hit enter when you are in the text box
This will disable all of the forms on the pages from being submitted:
$('form').submit(function() {
return false;
});
While this will "solve" your problem, you should target your form specifically, and use custom JavaScript behavior for submitting the data (e.g. using $.ajax).
For more advanced debugging use the following:
$(window).keydown(function(event) {
var breakpoint = 1; // Place a breakpoint on this line!
// Then use the "step out of current function" button to
// continue through the JS that gets executed... much of it
// will likely be native code, but if you pay attention to
// the native function names, you should eventually see the
// event that is causing the reload.
});

Categories