Interactive pop-up messages created with CSS and JavaScript that appear and fade based on the URL query string

I have a referral form on this page that I want people to use repeatedly.

After submitting the form, it reloads the page with the query string ?referralsent=true so users can refer more people through the form.

However, I also want to show users a confirmation message after they send an invitation.

To achieve this, my idea is to briefly display a popup message saying "Invitation sent" for a couple of seconds following the reload, which would then fade out.

I'm not sure how to implement this feature. Do you have any examples or tips on how to make it happen?

Answer №1

If you want to show a message after a certain amount of time using JavaScript, you can use the Timeout function:

Here is an example of how you can achieve this in your HTML code:

<div class="message hide" id="messageUser">
   <!-- Content for the hidden message -->
</div>

And here is the CSS styling for the message and the "hide" class that will initially hide it:

.message {
  display: block;
  border: 2px solid #ccc;
  padding: 20px;
}

.hide {
  display: none;
}

Finally, here is the JavaScript code that will remove the "hide" class from the message element after a 2-second delay:

setTimeout(function() {
  document.getElementById('messageUser').classList.remove('hide');
}, 2000);

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 incorporate a user-controlled autoscroll feature into this Carousel?

I am in the process of creating a "slideshow" using text boxes that can be scrolled with arrow buttons. My goal is to have the slideshow automatically scroll only until the user interacts by clicking one of the arrow buttons. Below is the state logic re ...

Retrieving Text following an HTML Element with a Parsing Tool

I'm currently utilizing PHP Simple HTML DOM for the development of a web scraper application. Here is the HTML structure from which we need to extract the City/State name, such as "Daviston, AL" in the example below. Can anyone assist me wi ...

Is it possible for a MySQL loop to only delete the first entry?

My MySQL looping is not working properly when I click the second button to get their id and continue with the rest of the process. Why is this happening? $(document).ready(function() { $("#deleteSchedule").click(function (e) { e.preventDefault(); ...

How to stop event propagation from a draggable element nested within a sortable container in jQuery UI

Here is a link to the code snippet: http://jsfiddle.net/Aa7TW/ {greedy: true} The issue arises with the interaction between droppable and sortable elements. Sortable is triggered when an item is dropped directly onto it, while dropping an item from the ...

What is the best way to implement momentJS globally in VueJS 2?

Currently working with Vue.js version 2.6.11 Trying to set up in main.js as follows: import moment from 'moment' moment.locale('nl'); Object.definePrototype(Vue.prototype, '$moment', { value: moment }); Encountering an error ...

Tips for effectively passing a $scope object between various controllers

I am encountering an issue with sharing a $scope object between two controllers. Within the 'IssueBookCtrl' controller, I update the 'books' object element value like this: $scope.books[i].issued = true; After that, I use the $emit s ...

Prevent webpage from resizing when window dimensions change

Whenever I resize my webpage window, the elements start to pile on top of each other and it looks disorganized. For example, when I reduce the window size, YouTube just cuts off everything instead of stacking the images. How can I achieve a similar effec ...

Using jQuery, you can dynamically switch pages by making asynchronous requests to the server using AJAX

Hey there! So I've got this JavaScript file with a function for a button that retrieves values from different checkboxes in a table. But now, I want to access these values on another page (for invoice processing). Here's the script: $("#boutonf ...

ClickEvent (or element selector) is experiencing functionality issues

I'm currently working on creating a small calculator using HTML, CSS, and JS. However, I'm facing an issue with selecting buttons of the calculator from the HTML script and adding EventListeners to them. Here is a snippet of my HTML code: `< ...

switch from ajax response to spring boot

I have encountered a situation that requires me to handle results obtained from an AJAX call in my Spring Boot controller. These results are displayed in a jQuery-accordion as per our customer's request. Now, the user should be directed back to the Sp ...

What is the best way to apply an outer border to a table using CKEDITOR?

Is there a way to only add an outer border to an HTML table in CKEDITOR? I've attempted to remove the inner borders using the advanced options in CKEDITOR, but it doesn't seem to be working. <table border="1" cellpadding="1" cellspacing="1" ...

What is the procedure for renaming an item within a basic array in Angular?

I am working on a project in Angular and have constructed an array. I am now looking to change the name of one of the items in this array. While I have figured out how to rename keys in an array, I'm still unsure about how to do so for its values. ...

Regex pattern to replace the zero preceding two times within a string based on distinct criteria

I need to transform the string XY4PQ43 using regex in JavaScript. The output should be XY04PQ0043. Specifically, I want to add a zero prefix to the first number if it is a single digit to ensure it has 2 digits, and for the second number in the string, I w ...

Using jQuery to create divs that can both be dropped onto and scrolled

I'm currently facing an issue with jQuery UI's droppable component. I'm unsure if the problem lies within my code or if it's a bug in the component. Within a div with fixed width and height, I have multiple inner divs that make the out ...

The font face feature does not seem to be functioning properly in the IE browser

I'm facing an issue with font face in a jQuery popup. It seems to be working fine on Chrome and Firefox, but it's not rendering properly on IE browsers. Font Face Code in css ---------------------- @font-face { font-family: "pt-sans"; sr ...

Restrict the height of posts created in the summernote editor

My goal is to create a structured page application using summernote. When using summernote, a div with contenteditable=true is appended to the body to allow users to add content. However, I want to set a fixed height for this div so that users can only ent ...

Issue with jquery.validate.js in an MVC 4 Project using jQuery 1.9

Recently, I set up a new ASP.Net MVC 4 project using the default template in Visual Studio 2012. However, I encountered an issue after updating to jQuery 1.9 where the login functionality stopped working. The specific error message that appears is: 0x80 ...

Transmitting data via POST method within datatables ajax call

I am facing an issue while attempting to execute a simple ajax call in datatables that relies on a post array of IDs from a form on a previous page. The error I encounter is: Invalid JSON Response This indicates that the JSON array being returned may be ...

When adjusting to mobile dimensions, the responsive website design struggles to center the navbar properly

I am currently developing my senior year portfolio website and I am struggling to center the navbar (Work About Contact) when it is in mobile mode. My goal is for it to be positioned directly below the logo, perfectly centered, but so far nothing I have tr ...

Error: 'fs' module not found in React.js and cannot be resolved

Encountering issues with tatum io v1 + react? Developers have acknowledged that it's a react problem which will be addressed in V2. In the meantime, you can utilize tatum io V1 with node js. I've included all dependencies that could potentially ...