When using the Javascript confirm box with a yes/no option, it may display the confirm box, but instead of waiting for the user to click Yes, it jumps ahead

JavaScript function:

   if (s12.value < s10.value) {
       $('<div></div>').appendTo('body')
           .html('<div><h6>' + "Out Time is less than In Time. Is that ok??" + '</h6></div>')
           .dialog({
               modal: true,
               title: 'Confirmation',
               zIndex: 10000,
               autoOpen: true,
               width: 'auto',
               resizable: true,
               buttons: {
                   Yes: function () {
                       if (s10.value < s14.value || s14.value < s12.value) {
                           alertDialog("Time is not between out time and in time.");
                       } else {
                           $("#<%=Button1.ClientID%>").submit();
                       }
                       $(this).dialog("close");
                   },
                   No: function () {
                       $(this).dialog("close");
                   }
               },
               close: function (event, ui) {
                   $(this).remove();
               }
           });

       < script >
           function alertDialog(message) {
               $('<div></div>').appendTo('body')
                   .html('<div><h6>' + message + '</h6></div>')
                   .dialog({
                       modal: true,
                       title: 'Errors',
                       zIndex: 10000,
                       autoOpen: true,
                       width: 'auto',
                       resizable: true,
                       buttons: {
                           Ok: function () {

                               $(this).dialog("close");
                           },

                       },
                       close: function (event, ui) {
                           $(this).remove();
                       }
                   });
           };

The first condition:if (s12.value < s10.value), prompts a confirmation box with the message "Out Time is less than In Time. Is that ok??"

If the user selects Yes, then check the second condition:

if (s10.value < s14.value || s14.value < s12.value)
, if it's true, display an alert box.

Otherwise, submit the form.

Issue: The form is submitted automatically without waiting for the user to interact with the confirm box.

Requesting assistance. Thank you.

Answer №1

It is recommended to create a dialog without opening it immediately

 var new_dialog = $('<div></div>').appendTo('body')
 .html('<div><h6>' + message + '</h6></div>')
 .dialog({
 modal: true, title: 'Errors', zIndex: 10000, autoOpen: false,
 width: 'auto', resizable: true,
 buttons: {
 Ok: function () {
   $(this).dialog("close");
 },


function displayDialog(message) {
  $(new_dialog).dialog("open");

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a fashionable look for your social sharing buttons

Using Social sharing button APIs from platforms like Facebook, Twitter, and Google Plus, I have created a basic fiddle for sharing a link (e.g. http://www.google.com). Check out the Fiddle Although my fiddle is functioning correctly, I am facing an issue ...

Retrieve the HTML element corresponding to the button that was clicked

How can I use jQuery to retrieve the HTML element containing the button that was clicked? Once a button is clicked, I need to obtain the invite object associated with that button and then send a post request to a specific URL. {% if invites %} {% for ...

Trouble selecting options in hierarchical data

I've been attempting to run this sample code for selecting an option from a select element with hierarchical data, but it seems to be having some issues. $scope.options = [ { id: 1, info: { label: "Item 1" } }, { id: 2, info: { label: ...

Click on the link to see the jQuery effect in action

I'm trying to achieve a fade-out effect on the current page followed by fading in a new one. The fade-in effect is working fine, but when I click on the link, the new page loads without first fading out the existing content. The div that I want to app ...

Tips for Removing Numbers from a Doughnut Chart in ChartJs 2 upon Initialization

I am currently struggling with a doughnut chart that is displaying data numbers on the chart segments upon loading, making it appear cluttered. I have attempted to remove these labels using the following code: Chart.defaults.global.legend.display = false; ...

Change the height of a division element after a script has been loaded

My web application is created using Bootstrap and Flask and it loads a Bokeh server document into a container div. The responsiveness of the Bokeh elements' size depends on a specific fixed initial height set for the containing div. This customization ...

Attempting to engage with the like button on a Facebook page through Python's Selenium seems to be problematic

Here is the code for adding a (Facebook page like button): WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.XPATH, '/html/body/div[1]/div/div[4]/div/div[1]/div/div[1]/div[2]/div[2]/div/div/div[3]/div/div[1]'))).click() The clic ...

"Troubleshooting the issue of ng-init not functioning properly in conjunction

I need help with displaying a list of numbers inside a div element. I am attempting to achieve this using the following code snippet: <div ng-init="range=[1,10,3,4,5]" ng-repeat="n in range" > {{n}} </div> Unfortunately, the numbers withi ...

Tips for maintaining position when refreshing a web page within a scrolling table

Recently, I came across a helpful tutorial on how to create a table with a fixed header and scrollable body. You can find it here. While the tutorial worked perfectly for me, I encountered an issue when trying to refresh the webpage and maintain my positio ...

Align a div both horizontally and vertically using only JavaScript

Is there a way to center a div both horizontally and vertically without knowing its height/width using pure JavaScript instead of jQuery? I have been able to achieve it with jQuery but want to avoid dependencies. Any ideas on how this can be accomplished ...

Recently updated to the latest versions of Angular, AngularCLI, and Rxjs (version 6), however encountering an error stating "Property 'take' does not exist on type 'Observable'"

Recently, I made the decision to update my Angular5 project to Angular6 and upgraded all dependencies along with it (such as rxjs now at version 6 and angular-cli). However, I have encountered a problem that is proving difficult to resolve: ERROR in src/ ...

Refreshing a div using JQuery/Ajax upon an update to a column in a database table

I am interested in checking for database column value changes and utilizing jQuery/Ajax to load a specific page into a designated div container. For example, let's say that on the main page, I have 1.php displayed within a div with the id "status." ...

My React project is unable to locate a file after I modified its extension from .js to .tsx

After using npx create-react-app my-app to start my React project and adding Typescript, I encountered an issue after converting one of my components to a .tsx file. The error message I received was: Module not found: Error: Can't resolve './cont ...

Preventing access to drives and desktop until the mandatory HTML form is completed

Looking to develop a webpage in JSP that will automatically open whenever my system is started. Users will be required to fill out a form on this page before proceeding further. If they attempt to bypass filling out the form, they should not have access ...

Challenges with creating an increment and decrement form component using Vue

I've been working on this for almost three days now. My goal is to create a reusable component in Vue that allows a passed value to be incremented and decremented with the click of a button, and then submitted in a form. Below is my code: Parent Com ...

insert a new empty row into an HTML table on the fly

I'm working with the code below and attempting to insert an empty row into a table whenever the date changes: <?php $old_date = $crew_rows[0]["date"] ?> <?php foreach ($crew_rows as $crew_row):?> <tr > <td style="text-align ...

Generate unique div elements randomly using jQuery and Javascript to populate a container

My website has a section that spans 100% width and is 450 pixels tall. This is the HTML structure... <section class="interactive-banner"> <figure></figure> </section> I am aiming for each 'figure' element to be 150 ...

How do you set a default value for a dropdown menu (<select>) and then update it later on?

In my grid, each row has a dropdown menu and I want to display its state from the database. The dropdowns are defined with a selected option specified for preselecting the value from the DB. <select id='selectId'> <option value='1& ...

Is there a way to obtain the guild ID during the createGuild event?

Can someone please help me figure out how to get the guild id in the event guildCreate.js? I have tried using guild.id but it returns undefined. Even when I use console.log(guild), it shows a blank space. Using client.guild.id throws an error for id. cons ...

What is the best way to run a function after 10 seconds of inactivity using jquery?

Can anyone help me figure out how to run a function every 10 seconds when the system is idle? Here's an example: setInterval(function () { test(); },10000); //for every 10 Sec I really need assistance in getting this function to ...