Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8916637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:17:21+00:00 2026-06-15T05:17:21+00:00

My apologies for writing such a lengthy question but I was asked to clarify

  • 0

My apologies for writing such a lengthy question but I was asked to clarify several details about the function

What would be the correct way to add another element to these If Statements if I want to call it by class or data-name (or another method which doesn’t require creating separate If Statements for each element which will utilize it)?

The function is used on pairs of 2 interconnected elements (who’s classes are complaint and ranking). The name of the 1rst Element matches the data-name of the 2nd Element, and since the function already identifies data-name of “ranking” maybe it can say that the name of the 1rst element = data-name of the 2nd element?

if ($(this).val() == 1 && !$(this).data("decrease_priority1")) { ... }
if ($(this).data("decrease_priority1") && $(this).val() != 1) { ... }

Here’s what I’m trying to do:

1rst If Statement – Set element if values are: “.complaint” = “Too_small” AND .”ranking” = “1”
2nd If Statement – Update element if values are: “.complaint” = “Too_small” OR .”ranking” = “1”

This 2nd element is the value of the select tag under the .complaint class, however there are several element with the same class so I need a way to specify which one it is. I’m trying to avoid using ID’s because there are 25 Select elements (so well over 100 combinations).

Method I’ve Tried

This doesn’t work properly (It doesn’t accept input unless the 1rst pair (Shoulders) is selected before the 2nd pair (Waist))

if ($(".complaint select").val() === "Too_small" && $(this).val() == 1 && !$(this).data("increase_priority1")) 
{ ... }

if ($(this).data("increase_priority1") && ($(this).val() != 1 || $(".complaint select").val() != "Too_small")) 
{ ... }

What the function does

The purpose of this Change function is to take all the complaint names selected (i.e. Shoulders, Waist) and group them into actions (i.e. increase or decrease) by ranking, so there are different functions that get called for the various combinations – in this case “Too_small” AND “1”. This snippet adds values to “increase_priority1” when the user selects both a complaint and ranks the importance level of the issue, and removes the value when the user changes either element.

If you want to see this in context, I created 2 fiddles. The first is of the existing script http://jsfiddle.net/chayacooper/vWLEn/171/ and the second is a working example of what I’m trying to do but it uses ID’s to do so http://jsfiddle.net/chayacooper/gYtZw/61/

Javascript

var $increase_priority1 = $(".increase_priority1");
// variables for other issues and priority levels go here

$(".ranking").change(function () {
    var name = $(this).data("name"); // Gets data-name of ".ranking" 

    // Sets & Unsets increase_priority1

    // I need to change this to state If values are "Too_small" AND "1" AND (...)  
    if ($(this).val() == 1 && !$(this).data("increase_priority1")) {
        //rank is 1, and not yet added to priority list
        $("<option>", {text: name, val: name}).appendTo($increase_priority1);
        $(this).data("increase_priority1", true); // flag as a priority item
    }
    //If either ranking or complaint value changes 
    if ($(this).data("increase_priority1") && $(this).val() != 1) {
        //is in priority list, but now demoted
        $("option[value=" + name + "]", $increase_priority1).remove();
        $(this).removeData("increase_priority1"); // no longer a priority1 item
    }
    // Similar If Statements go here to set & unset elements for other priority types
});

If the value of $increase_priority1 is “Shoulders”, complaint was Shoulders too small (select name=Shoulders value=Too_small), and it was assigned a level 1 priority (select class=”ranking shoulders” value=1).

HTML

<label>To Increase - 1rst Priority
<select name="modify_increase_1rst[]" class="increase_priority1" multiple></select></label>    
<span class="complaint"><label>Shoulders</label>
<select name=Shoulders><option value="null">Select</option><option value="Too_small">Too Small</option><option value="Too_big">Too Big</option><option value="Too_expensive">Too expensive</option>   
</select></span>
<label>Ranking</label>
<select name="importance_bother_shoulders" class="ranking shoulders" data-name="Shoulders">
    <option value="Null">Select</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option>
    <option value="5">5</option>
</select>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:17:23+00:00Added an answer on June 15, 2026 at 5:17 am

    Special thanks to @Lorax for helping me figure this out 🙂

    I’ve included the final code below and created a working example of it at http://jsfiddle.net/chayacooper/6YnQd/42/

    Javascript

    $('.complaint select.complaintOpt').change(function() {
    var $container = $(this).parent(),
        $item = $container.find('.complaintItem'),
        itemId = $item.attr('id'),
        itemVal = $item.val(),
        itemText = $item.find('option[value=' + itemVal + ']').html(),
        rank = $container.find('.complaintRanking').val();    
    // Ignore if not a complete complaint
    if((itemVal == 'Null') || (rank == 'Null')) {
        return;
    }    
    // Remove any existing complaint
    $('select.priorityIssue option.' + itemId).remove();    
    var $selectedOption = $item.find('option:selected');
    var targetBase = '';
    if($selectedOption.hasClass('goal-increase')) {
        targetBase = '#priorityIncrease';
    }
    else if($selectedOption.hasClass('goal-decrease')) {
        targetBase = '#priorityDecrease';
    }    
    if(targetBase != '') {
        // Add new complaint
        $(targetBase + rank + 'Issues')
            .append($('<option>' + $item.attr('name') + '</option>').addClass(itemId));
    }
    });
    

    HTML

    <label>To Increase </label><br/>
    <label for="priorityIncrease1Issues">First Priority</label>
    <select name="modify_increase_1rst[]" id="priorityIncrease1Issues" class="priorityIssue" multiple></select>
    <label for="priorityIncrease2Issues">Second Priority</label>
    <select name="modify_increase_2nd[]" id="priorityIncrease2Issues" class="priorityIssue" multiple></select>
    <br/>
    <label>To Decrease </label><br/>
    <label for="priorityDecrease1Issues">First Priority</label>
    <select name="modify_decrease_1rst[]" id="priorityDecrease1Issues" class="priorityIssue" multiple></select>
    <label for="priorityDecrease2Issues">Second Priority</label>
    <select name="modify_decrease_2nd[]" id="priorityDecrease2Issues" class="priorityIssue" multiple></select>
    <br />
    <div class="complaint">
    <label for="shoulders">Shoulders</label>
    <select name=Shoulders id="shoulders" class="complaintOpt complaintItem">
        <option value="Null">Select</option>
        <option value="too_big" class="goal-decrease">Too Big</option>
        <option value="too_small" class="goal-increase">Too Small</option>
    </select>    
    <label for="shouldersRanking">Ranking</label>
    <select name="importance_bother_shoulders" id="shouldersRanking" class="complaintOpt complaintRanking">
        <option value="Null">Select</option>
        <option value="1">1</option>
        <option value="2">2</option>
    </select> 
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies if this is too ignorant a question or has been asked before. A
Apologies for the seeming obviousness of this question, but for whatever reason I haven't
Apologies if this is not a typical SO question, but I'm hoping that someone
Apologies if this is a simple question, I'm still pretty new to this, but
Apologies for what is probably a newbish question. I am writing some Powershell scripts
apologies if I don't explain this clearly, but I'm writing an app which is
I'm writing my first iPhone app and, apologies, if this is the wrong forum
Apologies, It looks like my original question was not able to correctly explain what
Apologies for the poor question title. I have two tables, jobs and Persons-Jobs. Jobs
Apologies if this question is a bit obscure, I've been banging my head against

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.