Shutting down the Fancybox Window

Included in this code is a button that triggers the opening of a fancybox containing a form. Once the form is filled out and submitted, I want the window to close automatically and be replaced by another window displaying a success message. This success message should disappear after a few seconds or if the user clicks outside the window.

$("form").submit(function() { //Update this part
    var th = $(this);
    $.ajax({
        type: "POST",
        url: "mail.php", //Update this part
        data: th.serialize()
    }).done(function() {
        $('#alert-massage').fadeIn(500);
        alert("Thank you!");
        setTimeout(function() {
            // Additional actions once the form is submitted
            th.trigger("reset");
        }, 1000);
    });
    return false;
});

<div id="modal">
<div class="modal__wrap">
    <div class="modal__title">
        Contact Me
    </div>
    <form >
        <!-- Hidden Required Fields -->
        <input type="hidden" name="project_name" value="kylun-Serg">
        <input type="hidden" name="admin_email" value="[email protected]" >
        <input type="hidden" name="form_subject" value="popup-form">
        <!-- END Hidden Required Fields -->

        <input type="text" placeholder="Username" name="Name" required>
        <input type="email" placeholder="Email" name="E-mail" required>
        <input type="phone" placeholder="Phone" name="Phone">
        <textarea placeholder="Message" name="Message"></textarea>
        <button type="submit" class="btn">
        Send
        </button>
    </form>
</div>

Answer №1

By completing the form, you have the ability to trigger a specific function.

<button type="submit" onclick="myFunction()" class="btn">Send</button>

This function is designed to hide the modal, show a success message, and refresh the current page.

function myFunction(){
document.getElementById("modal").style.display = "none";
alert('Form submitted successfully.');
location.reload();
}

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

When navigating back to the Homepage from another page, React displays the Homepage

Recently, I started learning React and following the Traversy crash course along with an additional video on React router 6+. My route setup looks like this: import { BrowserRouter as Router, Route, Routes } from 'react-router-dom' return ( &l ...

What further steps are necessary beyond simply linking the Bootstrap css and js files in order to fully utilize Bootstrap classes?

While generating dynamic HTML, I've referenced bootstrap CSS and JS along with jQuery to apply a bootstrap class to an h1 element. However, the appearance of the h1 text remains unchanged. The key part of the HTML is being generated by the following c ...

Step-by-step guide on building an engaging Donut chart using jQuery

After spending several hours working on it, I'm struggling to draw my donut graph with JavaScript. Can anyone provide a solution? I am looking for a way to add 25% when one checkbox is selected and +25% when two checkboxes are selected. Thank you in a ...

Creating a binary tree using PHP-language

Currently seeking a reliable library or API to create a binary tree using PHP. I attempted to use Image_GraphViz without success and found phpsyntaxtree lacking in documentation. In addition, I am interested in a jQuery plugin that can achieve this task. ...

Creating dynamic JSON endpoints using JSP with Spring MVC

When working with JSON in my webapp, I have successfully passed a variable wordId to the Spring-mvc Controller using a static URL. However, I am unsure of the best practice for dealing with dynamic or parametric URLs. Controller Section: @RequestMapping( ...

Implementing row updates using contenteditable feature in Vue.js

I am currently exploring how to detect and update the changes made in a 'contenteditable' element within a specific row. <tbody> <!-- Iterate through the list and retrieve each data --> <tr v-for="item in filteredList& ...

How to target labels in CSS that end with a colon (*:)

Can CSS target labels that end with an asterisk and colon combination? Is this achievable? Let me elaborate further as per your request: Apologies if my explanation was not clear. I am working with an HTML label element that may end with an asterisk and ...

One particular Django template is failing to load the CSS, while the rest of the templates are

In my folder, I have two Django templates. One template is for the URL localhost:8000/people and it correctly fetches CSS from /m/css/style.css. The problem arises with the second template meant for the URL localhost:8000/people/some-name. This template f ...

I am having trouble with my scripts not working on a rendered partial view after using ajax to render it. Specifically, my datetimepicker is not functioning properly

I have implemented the following action on my controller: public ActionResult Absent() { Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1)); Response.Cache.SetNoSto ...

Actively toggle the selection state within OpenSeadragon

Currently, I am in the process of integrating a viewer for scanned pages using OpenSeadragon along with the Selection plugin (https://github.com/picturae/openseadragonselection) to allow users to select a portion of the page. I have successfully incorpora ...

The iPad Overlay fails to fully extend across the screen

I have implemented a modal div as an overlay to disable the background page while the overlay DIV is open. Below is the code I am using: #TB_overlay { height: 100%; left: 0; position: fixed; top: 0; width: 100%; z-index: 100; } Al ...

Rendering components before ComponentDidMount runs and Axios handles state updates

When I try to pass the gifs state to my GifList component in the render method, I encounter an issue. It seems that when trying to access the array within the component through props, it is returning as undefined. After investigating further, I noticed t ...

What is the procedure for defining a variable within an ng-container?

Within another section of my Angular 12 web application, I currently utilize an ng-container with *ngFor to loop through an array and exhibit a control for each item in the array. This is how it's implemented: <ng-container *ngFor="let paramet ...

html The selection in the dropdown menu is not showing the expected value

When using Firefox version 46.0.1, I encountered an issue with a select element that contains a value attribute being altered by Javascript code. Despite this change being confirmed in the browser inspector window with the select element showing a new valu ...

Is it possible to customize the weight and color of the border in the Material UI Dialog?

Hi there! I've been attempting to incorporate an external frame onto the Dialog Box from Material UI, but haven't had much success. I tried the following code snippet without any luck: overrides: { MuiDialog :{ paper : { borderWidth ...

Selecting arbitrary elements from an array to generate a fresh array

I am working on a project where I need to select three random values from an array and display them in a new array on my website. It is important that each value is only selected once. Here is what I currently have: var students = ["Hans", "Ole", "Nils" ...

Utilizing Fancybox with a polymer paper-card: A step-by-step guide

I have a collection of paper-cards and I am looking for guidance on integrating the fancybox library to display the content of each paper-card. Here is a sample of a paper-card: <paper-card heading="Emmental" image="http://placehold.it/350x150/FF ...

Struggling with integrating HTML Canvas within Vue.js

Currently, I am attempting to upload an image by utilizing HTML canvas. My decision to use canvas stems from the fact that I will be superimposing additional images based on the data received from the API, and this process seems more straightforward when u ...

Question about HTML Class. Explain the meaning of the hyphen (-) in a class

https://i.sstatic.net/wCbvo.png When looking at this image, is the '-' symbol serving as a connector between two ids or is the entire 'fa-facebook' considered an id? ...

Creating a script to randomly target a player with a monster in javascript

My latest project involves developing a game using Vue.js with characters like tank, DPS, and healer. data: { tankHealth: 100, healerHealth: 100, dpsHealth: 100, monsterHealth: 200, gameRunning: false, turns ...