Tips for showing a popup alert depending on a specific value

My dropdown menu includes the options

nothing, name1, name2, name3, name4 and more,...
. I want an alert popup to display only when I select nothing, but not when I choose any of the other options.

Any suggestions on how to achieve this?

Answer №1

$(document).ready(function(){
     $("#dropdown_change").change(function(){
    if(document.getElementById("dropdown_change").value == "nothing"){
    alert("nothing");
    $("#popup").css("display", "block");
    }
     });
   });
#popup{
    position: fixed;
    margin:auto;
    background: rgba(0,0,0,0.5);
    display: none;
    top: 0;
    left: 0;
    bottom:0;
    right:0;
    width: 300px;
    height: 200px;
    border: 1px solid #000;
    border-radius: 5px;
    padding: 5px;
    color: #fff;
} 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<!DOCTYPE html>
<body>
<form id="myform">

   Choose an option from the dropdown menu:
 
   <select id="dropdown_change">
      <option value="name1">name1</option> 
      <option value="nothing" id="open-popup">nothing</option>

      <option value="name2">name2</option>
 
      <option value="name3">name3</option>
  
      <option value="name4">name4</option>
   
    
</select>
</form>
<div id="popup"> POP UP</div>
</body>

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

store the response from XMLHttpRequest in a JavaScript variable

This question has been asked twice before, but I still couldn't get it to work. After reading through the posts here and here, I learned about calling a callback function because the XMLHttpRequest is asynchronous (which seems obvious anyway). So, I ...

The CSS and JS codes are not successfully integrating into the webpage

I am encountering an issue with loading CSS and JS files onto my page. My project involves PHP and Xampp. The file structure is as follows: My Site - CSS - index.css - JS - index.js - Index.php (Apologies for the lack of a folder tre ...

Tips for connecting multiple queries in Neo4j through the NodeJS driver and combining data into a new property

In my NodeJS project, I am developing an import function for a list of tagged elements in Javascript object format. This list may contain duplicates as it is a combination from multiple sources. Here is an example list (from test.json): [ ... ] The ...

Tips for properly documenting varying numbers of parameters in specific scenarios using JSDoc

Is there a way to document in JSDoc that my function only requires the second and third parameters when the first one is not equal to 3? getTimeframe: function(timeframe, since, until) { /* * @param {Number} timeframe Can be 0, 1, 2, or 3 * @param {Nu ...

Sync user information when alterations are made on a different device

As I create a Discord clone using Next.js, I've encountered an issue where when a server is deleted, another client can still see and use the server until the page is reloaded. When testing out the official Discord web app, changes seemed to happen in ...

Stopping the interval in Javascript on button press

Struggling to make clearInterval work properly when connected to a button click action. Also, the function seems to be activating on its own... Take a look at my code below var funky = setInterval(function() { alert('hello world'); }, 2000); ...

Unable to retrieve the image

When trying to fetch an image, I encountered the following error: Failed to load resource: the server responded with a status of 404 (Not Found) TopBar.jsx import { useContext } from "react"; import { Link } from "react-router-dom"; ...

The userscript will keep the window open as long as it remains inactive

Hello everyone, I'm excited to join the StackOverflow community and dive into userscripts for the first time! Putting aside any unnecessary details, I'm encountering a small issue with a script I recently created. (function () { $("#enbut"). ...

Strategies for managing dynamically mounted component events

I have a widget defined as: Calculator.vue <template> ... </template> <script> export default { data: function () { return { value: 0, }; }, methods: { ... ...

Enhancing Rails: Tailoring the flash message to suit individual needs

I am embarking on my journey with ruby on rails and could use some guidance with the following scenario. In the application.html.erb file, flash messages are configured to fade out after a few seconds by default. <div id="message" class="modal alert a ...

Loop through data and use jQuery to insert it into the server

I am encountering an issue with my code as I attempt to insert data from a loop; unfortunately, I keep getting the error message "Uncaught TypeError: Illegal invocation". window.items = ''; _.forEach(cart.items, function(n, key) ...

Delay the closure of a window by utilizing a straightforward method when selecting the "X - CLOSE" option with the following code: `<a href="javascript:window.open('', '_self').close();">X - CLOSE</a>`

I need to implement a delay when users click on the link to close a window. The purpose of this delay is to allow time for playing random "signoff" audio files, such as "Thanks!" or "See you next time!". Currently, without the delay, the audio stops abrupt ...

Having trouble accessing req.user on my Node.js server using Auth0 and Angular

Currently, I am utilizing auth0 for my admin panel's login system and it is functioning smoothly. However, I have encountered an issue in node where 'req.user' is returning as undefined for some unknown reason. This setup is fairly basic; I ...

I am facing a challenge with AngularJS where I am unable to navigate between pages using the

I'm having issues with my route file app.js. Whenever I click on any link or button, it redirects me to books.html. What could be the mistake I'm making? var myApp = angular.module('myApp', ['ngRoute']); myApp.config([&apo ...

Implementing the Jssor slider

Recently, I've been using the jssor slider on multiple pages without any issues. However, I am now facing some challenges. Ideally, I want the slider to be hidden initially and then displayed with another script. While I have managed to achieve this v ...

What is the process for entering a value into mysql based on the date?

Seeking assistance with a specific coding challenge. The task at hand involves inputting a date, such as '2018-05-08', and based on the user's input, storing the value in different columns of a database table. For instance, if the date is &a ...

What is the process for invoking a window function in a universal React application?

When working with an Isomorphic react application, we utilize the same codebase for both client and server. However, one common issue is how to call a window.function() from inside a server-side (Node.js) call. Attempting to call a function in a third-par ...

What is the best way to arrange numerous objects within an array?

Here is the code snippet I am working with: const info = { detail : { id: "1", name: "aa", category: [ { id:"11", order:0, }, { id:"33", order:5, }, { id: ...

Trouble with Jquery's .next() function not behaving as anticipated

After loading my website, an unordered list initially appears empty. To populate it, I use jquery and ajax to fetch data from a database via a php page. The data returned by the ajax call is used to create list items which are then added to the unordered l ...

Modify the cost directly on the search results page using PHP

I am new to PHP and SQL and I have a question regarding updating the price on a search result page in PHP. I want to include an input field and a submit button that will allow me to update the price of books displayed in the search results. After submittin ...