Implementing a pop-up notification at the center of the display for empty fields

I am currently working on a task that requires me to display a pop-up message at the top-middle of the screen stating "please fill in all fields before submitting". This custom box should be stylable using CSS.

Although the solution seems simple, I am struggling to figure out how to implement it.

The given code lacks documentation on how to achieve this. Do I need to create a separate div for the pop-up box and a function to trigger it? Perhaps by calling the function within the if statement?

I apologize if my explanation is unclear or doesn't make sense, as I am still relatively new to this (as you can probably tell).

Thank you in advance!

var requiredFields = [ "firstname", "lastname", "email", "message" ];

function checkContactForm() {
  var theForm = document.forms[0];

  for (var i in requiredFields) {
    var fieldName = requiredFields[i];

    if (!theForm[fieldName].value || theForm[fieldName].value == "Error") {
      theForm[fieldName].style.color = "#f66";
      theForm[fieldName].value = "Error";

      var emptyFields = true;
    } 
  }

  if (!emptyFields) { theForm.submit(); }
}

function resetField(theField) {
  if (theField.value == "Error") {
    theField.value = "";
  }
  theField.style.color = "#000";
}

Answer №1

Have you considered using a jQuery UI .dialog, like in this example: http://jsfiddle.net/csdtesting/aL14evyk/

$("#dialog-message").dialog({
    modal: true,
    draggable: false,
    resizable: false,
    position: ['center', 'top'],
    show: 'blind',
    hide: 'blind',
    width: 400,
    dialogClass: 'ui-dialog-osx',
    buttons: {
        "I've read and understand this": function() {
            $(this).dialog("close");
        }
    }
});

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

Utilizing NPM modules in the browser using Browserify for seamless integration

I'm attempting to utilize Browserify in order to make use of an npm package directly in the browser. The specific package I am trying to leverage can be found here Within my code, I have a fcs.js file: // Utilizing a Node.js core library var FCS = r ...

Retrieve all hyperlinks from HTML using C programming

Is there a way to extract all URLs from an HTML document using the C standard library? I attempted to use sscanf() for this purpose, but encountered errors when checking with valgrind. I'm unsure if my code will meet the requirements even after succe ...

Deciphering the mechanics of collection referencing in mongoose

Today, I am delving into the world of using references in mongoose for the first time. I am trying to figure out how to save a template with a user ID. Do we need to retrieve the createdBy value from the client, or can it be inserted into the templateSchem ...

AngularJS is unable to locate the $locationProvider module

I'm encountering an error message every time I attempt to utilize $locationProvider. Is there a specific way I should be importing the module? Error: $injector:unpr Unknown Provider Unknown provider: $locationProviderProvider <- $locationProvider ...

Can you explain the purpose of the bson type in conjunction with the javascript/javascriptwithscope?

I am intrigued by the utilization of the two types of bson, specifically javascript and javascriptwithscope, as the foundational types of bson. What are the use cases for these types and how can a javascriptwithscope object be created and saved in mongodb ...

Creating a span element to replace the list item class in a JavaScript Modal Pop-up

I recently set up a portfolio website that showcases my projects. When you click on a project, a modal window opens with a carousel gallery inside. On my .html page, the projects are organized like this: <li class="Project" data-modal="myModal_1"> ...

When the page is refreshed, the value bounces back and forth between

I've encountered a strange issue on my page with 6 textboxes. Whenever I enter values into these text boxes and then refresh the page, the values seem to jump to the next textbox (the one after the next). For example, if I enter values as follows: [ ...

adjusting the size and positioning of an image within a parent div using React

Hey everyone, I'm a newcomer to the world of React. Currently, I'm working on a website and everything seems to be falling into place nicely. However, I've encountered a little hiccup. My goal is to write code within my SCSS folder that will ...

What is the functionality of this JQuery Popup?

I'm facing an issue with my JQuery Popup. When the "Login" button is clicked, it hides the Login popup but doesn't show the Sign Up popup. How can I make sure that clicking on "Login" hides the Login popup and shows the Sign Up popup accordingly? ...

The expected behavior is not displayed when using Async.waterfall within a promise queue

In our software implementation, we have utilized a promise queue feature using the q library. The sequence of functions is structured as follows: PQFn1 -(then)- PQFn2 - .... Within PQFn1, an array of values is passed to a callback function implemented wi ...

Refresh a specific div element within an HTML file when the AJAX call is successful

After uploading the image, I want it to be displayed right away. To achieve this, I am looking to refresh the div with id="imagecontainer" within the success function of my ajax call. However, I would prefer not to rely on ("$id").load("href") as it does ...

Utilizing CSS Grid to create a modern layout design featuring a fullwidth header and footer,

I have a traditional website layout with a header, main content area with a sidebar, and a footer. I want the header and footer to span the entire width on wider screens, while the main content and sidebar are fixed width, surrounded by whitespace. When th ...

Achieving Full Height for Parallel Columns Divs with Bootstrap - A How-To Guide

I am struggling with getting two divs in parallel to have full height. Even though I have the divs side by side, when I try to set their height:100%;, nothing happens. What CSS properties do I need to modify to achieve this? The goal is to create a cove ...

What's the preferred formatting for a Jade Layout?

I've been struggling to convert this HTML code into Jade: <div class="textItem"> <div class="avatar"> <img src="http://wowthemes.net/demo/biscaya/img/demo/avatar.jpg" alt="avatar"> </div> "How many times ha ...

Implementing a feature in ReactJS that enables users to select a minimum and maximum limit for checkboxes

I have developed a unique React application that incorporates JSON values into checkbox elements. The JSON data includes both minimum and maximum required values. I successfully implemented a function to set the checkboxes' maximum value based on the ...

tips on utilizing the JSON information transmitted from the backend

$.ajax({ url: '{{ URL('reports/groupsUsersGet') }}', dataType: "json", data: { group_id : $('#group').val(), }, success: function(data) { <li>"i need to insert variable here"</li> }, error: function (data) ...

When I remove the `return false` statement in my code, my AJAX call executes successfully. However, keeping it in prevents the call from

I am using jQuery to send an AJAX POST request without refreshing the page. I have tried using the return false command to prevent the page from refreshing, but then the AJAX POST request doesn't go through. If I remove the return false command, the A ...

PHP and Bootstrap combine in this dynamic carousel featuring thumbnail navigation

Looking to create a dynamic bootstrap carousel with image thumbnails at the bottom? After exploring various code snippets and solutions, I stumbled upon this link. While the code worked, I found the thumbnails to be too small. Below are the functions I use ...

The Vue.js application is experiencing issues with displaying Google Maps functionalities

I have developed an application using Vue.js in Monaca and Cordova with onsenUI. My goal is to display my location on a Google map within the page. I attempted to achieve this by utilizing the npm package named vue2-google-maps, but unfortunately, it' ...

How can I troubleshoot the unresponsive remove div function on my website?

My code is running fine on CodePen (link provided below), but for some reason, it's not working properly in the web browser. I am executing the code from localhost and the button isn't responding as expected. CODE Here is my Visual Studio code ...