Steps to activate a faded background following a form submission triggered by an On change event

My goal is to implement a greyed-out background upon form submission without a traditional submit button. Instead, I want the form to be submitted when the user selects an option from one of three drop-down lists.

Here is a snippet of the form:

<form action="{{route('cats.filter')}}" method="post" id="myform">

Example of the select element:

<select class="custom-select" name="goalcat" id="goalcat" onchange="this.form.submit();">

The current issue lies in the JS code where the greyed-out background only appears when a drop-down list is opened before any selection is made. To fix this, I need to assign a valid ID for the JS code so that the overlay shows after form submission.

JS code snippet:

$("#myform").click(function () {
    $(".overlay").show();
});

CSS styling for the overlay:

.overlay {
    background: #e9e9e9;  
    display: none;        
    position: absolute;   
    top: 0;                  
    right: 0;             
    bottom: 0;
    left: 0;
    opacity: 0.5;
}

Answer №1

Here is a code snippet written in JavaScript:

function submitForm(){
var form = document.getElementById('myform');
form.submit();
var overlay = document.getElementById('overlay');
overlay.style.display = 'block';

}
#overlay {
  position: fixed; /* Positioned on top of the page content */
  display: none; /* Initially hidden */
  width: 100%; /* Full width covering the entire page */
  height: 100%; /* Full height covering the entire page */
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0,0,0,0.5); /* Black background with transparency */
  z-index: 2; /* Stack order above other elements */
  cursor: pointer; /* Cursor changes to pointer on hover */
}
<form action="" method="post" id="myform">
    <select class="custom-select" name="goalcat" id="goalcat" onchange="submitForm();">
       <option value=""> ABC </option>
       <option value=""> XYZ </option>
       <option value=""> LMCV </option>
       <option value=""> AFA </option>
    </select>
</form>

<div id="overlay"></div>

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

What steps can I take to convert my React class into a function in order to incorporate Material UI components effectively?

With Emailjs set up successfully, my next step is integrating Material UI text fields (link: https://material-ui.com/components/text-fields/#text-field) to enhance the design of my project. The challenge I'm facing is incorporating Material UI classe ...

Nested promises utilized within functional programming techniques

Working on an Angular project involves developing a booking system with various scenarios. The challenge lies in handling different server calls based on the response of a promise, leading to a nested callback structure that contradicts the purpose of prom ...

Mapping DOM elements to VueJS components for hydration is a key process in facilitating

I have a specific requirement and I am exploring potential solutions using VueJS, as it offers the convenient feature of hydrating pre-rendered HTML from the server. In my Vue components, I do not define a template within the .vue file, but I need them to ...

Issues with the dropdown menu functionality occurring on a .Net6 MVC app razor page

I recently created a dropdown menu using bootstrap. It functions perfectly when I load an HTML file in VScode. However, I encountered an issue when I tried using the same dropdown markup in a .NET6 MVC app's .cshtml file. When I click on the dropdown ...

eliminating identical items in an array

I've been working on finding and removing duplicate objects in an array, but I keep encountering an error when trying to access the filterList[i+1].tagID element. Strangely, manually inputting the [i+1] values seems to yield the correct results. I&apo ...

updating a div with URL redirection instead of global redirect

I am facing an issue with redirecting my website flow to the login page when a user clicks any link on the page after the session has expired (either due to timeout or manual logout from another window). In an attempt to solve this, I inserted the followi ...

Is it necessary to sanitize input fields manually in Angular 6?

Is it necessary for me to manually sanitize all user inputs, or does Angular handle this process automatically? In my login form, the data is sent to the server upon submission. Do I need to explicitly sanitize the data, or does Angular take care of sanit ...

When the submit button is clicked on a React form, it not only submits the current form

I am working on a React application with multiple forms, where each form is rendered based on the current page index. I would like the "Next" button that retrieves the next component to also act as a submit button. The issue I am facing is that while the n ...

Issue encountered while attempting to insert data into the database using a form. SQLSTATE[42S22]

Encountering an issue while attempting to extract data from a form and insert it into a table named objects within a database named test. Upon submitting the form with entered information, an error is triggered: Fatal error: Uncaught PDOException: ...

Validator returns undefined when expressing invalid data

Having an issue with validation, here is the code snippet: routes.js var express = require('express'); var router = express.Router(); var hello_controller = require('../api/controllers/helloController'); var { validationRules, validat ...

Exploring AngularJS: Extracting Data Using the GET Method

Here is my Controller: angular.module('apartmentCtrl', []) .controller('ApartmentController', function ($scope, $http, Apartment) { $scope.loading = true; $scope.myLocation = ''; Apartment.get($scope.myLocation ...

HTML - What steps can I take to ensure my website displays appropriately on various screen sizes?

Currently, I'm having some trouble with the appearance of my website. Let me explain: I've written some basic code (Please note that this code includes margins. I'm not sure if this is causing the issue) but the content doesn't display ...

"Encountering issues with getStaticPaths not generating any paths

I have a folder named data which contains a file called events.ts: export const EventsData: Event[] = [ { name: 'School-Uniform-Distribution', images: ['/community/conferences/react-foo.png', "/community/conferences/react ...

Display secret content upon hovering with a stylish animation

My current structure is as follows: HTML: <ul> <li> <span>asd</span> adsafsadlvjnsd </li> </ul> CSS: span { width: 0; } li:hover span { width: 60px; } In this setup, the content inside the span tag is h ...

Utilizing Chart.js to extract and display specific data values from an external JSON file

I am currently engaged in a journey of self-exploration where I aim to create a chart depicting the number of anime shows with comedy or fantasy genres. The data for my chart will be sourced from an external JSON file (anime.json) on my computer. Initially ...

extracting URL parameters using AJAX

I have successfully created an AJAX request using the GET method, passing variables to the URL and receiving a response. Now, I need to retrieve the current URL variables by clicking on a newly created button in order to proceed with further processing. Th ...

Using the codesnippet feature in CKEditor in combination with highlight.js

I am currently experimenting with implementing the highlight.js library in conjunction with the CKEditor addon called CodeSnippet. Although I have successfully integrated the CodeSnippet addon into my CKEditor, the code is not being properly detected, col ...

Tips for aligning text to the left within a Bootstrap accordion

I am in the process of developing a static website utilizing the W3schools "Company" theme. The complete code for this website, including CSS, is provided below: <!DOCTYPE html> <html lang="en"> <head> <!-- Theme Made By www.w3schoo ...

receiving a pair of components instead of just one

Here is the code for router.js: import React from 'react'; import { Route } from 'react-router-dom'; import CommentList from './containers/commentview'; import CommentDetalList from './containers/commentdetailview'; ...

Is there a way to narrow down the font choices using HTMLPurifier?

- Currently in my project, I have incorporated an HTML-WYSIWYG Editor that allows users to utilize various Webfonts for styling their texts. The editor I am utilizing can be found at NiceEdit. It generates code snippets such as: <font face="c ...