Choose distinct and original dialogue for every option selected

My goal is to design a unique confirmation dialog that will display for each option selected. Currently, I have it set up so that the dialog will only appear if the selected option is lower than the previously selected one. Everything seems to be working fine in that aspect except for the dialogs.

I have observed that when I change to a different option, the system is reading the data-model attribute for each option but sometimes it fails to trigger the correct dialog (you may need to keep switching through to notice it).

For instance, if I choose the Mono option, the alert correctly shows ('bus-outputs-reduce-width-to-mono), but then the dialog displays "reduce to Stereo". The inconsistencies vary each time, and I can't seem to figure out the reason behind this behavior.

It would also be beneficial if the option doesn't change until the user has pressed confirm (although I understand that I wouldn't be able to utilize the .change function, I'm unsure of what else to use).

Any suggestions?

HTML

<select class="bus-width btn-light-outline" data-modal="fader-layout-new">
    <option value="No Path" data-modal="bus-outputs-remove-bus">No Path</option>
    <option value="Mono" data-modal="bus-outputs-reduce-width-to-mono" selected="selected" >Mono</option>
    <option value="Surround" data-modal="bus-outputs-reduce-width-to-stereo">Stereo</option>
    <option>5.1 Surround</option>
  </select>

<div class="overlay">

    <a class="cancel">Cancel</a>
    <a class="confirm">Confirm</a>

<div class="hide" id="bus-outputs-remove-bus">Remove Bus?</div>
<div class="hide" id="bus-outputs-reduce-width-to-mono">Reduce to Mono?</div>
<div class="hide" id="bus-outputs-reduce-width-to-stereo">Reduce to Stereo?</div>

</div>

SCRIPT:

var lastIndex = null;

$('select.bus-width').on('change', function () {

    var thisIndex = $(this).find(":selected").index();
    if(thisIndex < lastIndex){
        var myModal = $(':selected').attr("data-modal");
        alert(myModal);
        $('#' + myModal).stop().fadeIn(300);
        $('.overlay').fadeIn(300);
    }

    lastIndex = thisIndex;

});


$('.confirm').click(function() {
    $('.overlay').hide();
});

CSS:

.overlay {
    position:fixed;
    background:rgba(0,0,0,0.5);
    top:0;
    bottom:0;
    right:0;
    left:0;
    text-align:center;
    display:none;
    z-index:99999;
}
.hide {
    display:none;
    position:absolute;
    width:200px;
    top:200px;
    left:50%;
    margin-left:-200px;
    background:red;
}
.cancel {
    background:white;
    position:absolute;
    top:270px;
    left:200px;
    padding:20px;
}
.confirm {
    background:yellow;
    position:absolute;
    top:270px;
    left:270px;
    padding:20px;
}

DEMO: http://jsfiddle.net/susannalarsen/47a21r25/

Answer №1

Feel free to take a look at my fiddle.

Adding the code snippet below should help address the issue of hidden modals not being displayed correctly.

UPDATED JavaScript

    if (thisIndex > lastIndex) {
        var selectedModal = $(':selected').attr("data-modal");
        alert(selectedModal);
        $('.hide').hide();
        $('#' + selectedModal).fadeIn(300);
        $('.overlay').fadeIn(300);
    }

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

Stop storing CSS data for nopCommerce

Currently, I am looking for a method to avoid caching CSS files on my nopCommerce website. In the past, I have achieved this by adding the date and another element at the end of the CSS call. Html.AppendCssFileParts("~/Themes/CustomTheme/Content/css/site. ...

The order of the data parameter in the $.ajax() method

Consider a scenario where my model is structured as follows: public class someModel{ public int age {get; set;} public string affiliation {get;set;} public string name {get;set;} } Now, let's assume that I am submitting a form someForm: ...

Leveraging JsonResult in combination with jQuery

I am in need of constructing a Json output for a jQuery plugin. The format required is as follows: [{ "name": "Testing", "desc": "OB-2014-0202", "values": [{ "Status": 2, "from": "\/Date(1391295600000)\/", "to": "\/Date(1392505200000)\ ...

What is the best way to animate elements so that they move in a circular motion?

My goal is to recreate the image shown in the picture: https://i.sstatic.net/z08II.jpg In case the image is blocked, you can view it here: https://i.sstatic.net/YYg4J.jpg The picture appears to have only one icon visible, but there are actually 4 icons. ...

What is the best way to reveal a hidden div using JavaScript after a form submission?

jQuery is not a language I am very familiar with, but I am attempting to display a simple animated gif when a form is submitted. When users click 'submit' to upload an image, I want the gif to show to indicate that the image is being uploaded. Th ...

"Adjusting the Height of an MUI Autocomplete Input Field: A Simple Guide

I've been attempting to shrink the size of the Input field in MUI autocomplete but haven't had any luck. Here's the code I tried: styling: autocompleteStyle: { height: '2.3rem', color: `${theme.palette.grayDark1} !important ...

My goal is to develop a table that is both able to be resized and easily repositioned

I've been working on a project to develop an interactive table that can be manipulated, resized, and repositioned within a canvas. The code snippet below shows my attempt at creating this table on the canvas: var canvas = document.getElementById("dra ...

How come there is such a large space for clicking between my logo and the navigation bar, and what can be done to eliminate it?

* { box-sizing: border-box; padding: 0; margin: 0; } ul { list-style-type: none; } .nav-links, .logo { text-decoration: none; color: #000; } .logo { max-width: 80%; width: 20%; height: 20%; } .navbar img { width: 10%; height: auto; di ...

Content in Bootstrap not filling entire mobile screen

The content in this form does not stretch to full screen on mobile phones, but it appears properly on computers and tablets. Please advise on how to solve this issue. https://i.stack.imgur.com/S2XkS.jpg <link rel="stylesheet" href="https://maxcdn.bo ...

Exploring the functionalities of jQuery within ajax-loaded content

My web page consists of the following code: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>test</title> <script src="jquery-2.1.1.min.js"></script& ...

Python requests no longer retrieves HTML content

I am trying to extract a name from a public Linkedin URL using Python requests (2.7). Previously, the code was functioning correctly. import requests from bs4 import BeautifulSoup url = "https://www.linkedin.com/in/linustorvalds" html = requests.get(url ...

When the redirect page includes a parameter, it has the ability to conceal the functionality of the subsequent page

I'm looking to redirect my page to another page while also triggering a hidden function on the next page. When I click on the redirect link, I want the page to redirect and for the function on the next page to be called as well. <script type="text ...

Resizing rectangular images with CSS/Bootstrap into perfect squares

Imagine there is a rectangular image with dimensions of 1400px (height) x 700px (width). I am looking to turn it into a square while maintaining its original proportions and having white sides added. I specifically do not want to crop the image - I want it ...

Want to learn how to create an image magnifier using just one image?

At first, I created an image magnifier that would zoom in when the user hovered over the image. However, now I am looking to switch to a lens zooming method that uses only one image. ...

Looking to reduce the size of a logo image within a container as you scroll down a webpage?

I've been working on creating a logo section for my website, but I'm struggling to make it shrink as users scroll down and expand back to its original size when they scroll up. I've tried various JavaScript and jQuery functions without succe ...

Using jQuery to create variables according to array elements

I'm uncertain if this is the correct way to define variables based on array values. The getParameterByName() function retrieves URL parameters var t = getTab(); var paramArray = { 'year' : 'y', 'condition' : 'c& ...

Having trouble compiling your Vue project and running into the "No mixed spaces and tabs" error?

Below are the details with an error: Error Details: Failed to compile. ./src/components/Header.vue Module Error (from ./node_modules/eslint-loader/index.js): H:\project\VueProjects\stock-trader\src\components\Header.vue 27: ...

How can I remove HTML tags from a string using .NET?

Does anyone know of an efficient way to strip HTML tags from a string of HTML text? ...

Please upload the image by clicking the "Upload Files!" button instead of relying on the input change

I am looking to enhance my image uploading process by allowing users to upload multiple images after clicking the Upload Files! button, rather than relying on the input change event. Below is the jQuery code I am using (which I found here): index.html &l ...

What is the correct way to include '?i#efix' in a font directory path in a Rails application?

It is suggested to include ?#iefix at the end of .eot font paths in order to resolve another erratic behaviour issue in IE: @font-face { font-family: 'MyWebFont'; src: url('webfont.eot'); /* IE9 Compat Modes */ src: url(&ap ...