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

Unable to modify the width of textarea

I've been struggling to adjust the width of a textarea element, as neither setting rows and cols in HTML nor using CSS has worked for me. The height adjustment was successful with HTML. Any tips on changing the width? form, label { position: rel ...

PHP code to send an HTML template via email:

When attempting to send HTML content in an email using my PHP mail code, I encountered an issue where the HTML template was not being sent along with the message. $to = $email;; $subject = 'New Order Detail&apo ...

Why isn't my Vue.js application automatically refreshing when I add or remove an object from the array?

In my Quasar and Vue.js project, I am working on a form where I can add objects to an array for insertion into the database simultaneously. However, I am facing an issue where the additions or deletions in the array only reflect on the screen after focusin ...

Executing a PHP function within the same file using AJAX: A step-by-step guide

I've been exploring online tutorials to learn about ajax as it's a new technology for me. My main goal is to understand how to utilize two functions, create() and population(), in a php file. The create() function generates a form like this: ma ...

Arranging elements in columns using Bootstrap

I am facing an issue with my columns in bootstrap, as they are currently appearing vertically, one above the other. I need them to be displayed side by side Here is the code I am using: <div class="col-xl-4 col-lg-6 col-md-6 col-sm-12 col-12 layo ...

Implement the usage of plainToClass within the constructor function

I have a dilemma with my constructor that assigns properties to the instance: class BaseModel { constructor (args = {}) { for (let key in args) { this[key] = args[key] } } } class User extends BaseModel { name: str ...

Refresh the div element's HTML and content using AJAX

I am interested in implementing a feature similar to the StackExchange link found on the top left of the Stack Overflow site. From what I gather, when the stack exchange link is clicked, the following actions take place: The hidden div container becom ...

the menu didn't glide into view

I'm currently working on implementing a stylish menu For this project, I am following a helpful guide that instructs to create the HTML in a single file. The issue is that the menu isn't sliding smoothly as expected. Here is the HTML code - no ...

Switching HTML text by clicking or tapping on it

I'm currently working on a website that will showcase lengthy paragraphs containing complicated internal references to other parts of the text. For instance, an excerpt from the original content may read: "...as discussed in paragraph (a) of section ...

When utilizing "column-count" with "display: flex", both Firefox and IE will only render a single column

I am struggling to achieve a two-column layout with nested columns inside each one. The code I used looks great on Chrome and Safari, but on Firefox and IE, it only displays in a single column: What mistake am I making here? .two-columns { column-cou ...

Toggle switch unable to reset upon reloading the page

Issue with Toggle Switch Not Resetting on Page Reload I am encountering a problem with a toggle switch I implemented from the W3schools example (link here). Unlike in the W3schools editor where it resets its state upon reload, my toggle switch remains in ...

Tips for showcasing array values on an HTML webpage

Having trouble displaying the "latitude" and "longitude" in html. I attempted to use a forEach loop, but it was not successful this.otherService.getList().subscribe( (response: any) => { this.atm = response; HTML <div class="item" * ...

Steps to connect my CSS with my HTML in a website hosted on GitHub

I am experiencing an issue with my website hosted on Github pages. It seems to be unable to read the CSS file that I have linked to it. Here is a snippet of my HTML code: <!DOCTYPE html> <link rel="stylesheet" type="text/css" href="https://githu ...

Have you ever wondered why req.body returns as undefined when using body parser?

Every time I attempt to make a post request, I keep receiving an error message stating that req.body is returning as undefined. Below is the content of my server.js file: import express from 'express'; import bodyParser from 'body-parser&ap ...

Looking to create a row-column-row layout using CSS flexbox techniques

` I am trying to create a unique row-column-row layout using CSS flexbox. Below is the code snippet I have: * { padding: 0; margin: 0; box-sizing: border-box; } .container { display: flex; flex-wrap: wrap; gap: 0.2%; } .box { color: whit ...

Reduce the number of divs on a webpage while incorporating animated transitions

I've been attempting to incorporate an animation on the width property for my div .panels. I've tried using transition-property in CSS and also with .animate() in jQuery, but unfortunately, it doesn't seem to be working. I also noticed that ...

The specified font-size in my CSS is being ignored by Chrome

I'm a beginner in the world of html/css and was tasked with creating a html webpage. I set a specific font-size for my webpage, only to be surprised when my browser (Google Chrome) adjusted it on its own. Even though I specified the font-size as 14px, ...

Tips for preventing redundant data entry in a table

Currently, my table displays like so: The structure of the HTML for the table is as follows (only a snippet is shown, as the rest looks similar): <table class="table table-bordered table-condensed"> <tr> <th>Days</th> ...

Utilizing jQuery to dynamically load CSS files on a webpage

For my website, I have implemented 4 different .css files to handle various screen resolutions. Here is the innovative jquery code I've developed to dynamically load these files based on the width of the screen. <link id="size-stylesheet" rel="st ...

Confirming the validity of an email address with Md-chips

Email Validation for MD-Chips Struggling with creating an email validation for md-chips. The current expression I'm using is not working as expected, since the ng-keypress directive is triggered every time I type something. Any suggestions on how to ...