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 8686409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:50:27+00:00 2026-06-12T22:50:27+00:00

I have an function where I have some drop-downs. I have some values where

  • 0

I have an function where I have some drop-downs.

I have some values where I have to check whether the values exist in the dropdown.
If they exist I have to keep them and remove other options from my dropdown

This is what I have been trying to do

function getimage(value, ProdId) {
  $.getJSON("/api/ProductDetails", { option: value, productid: ProdId }, function (data) {
    $.each(data, function (idx, product) {
      $('#defaultimage').empty();
      $('<img id="dfltimage"/>').attr({ src: product.ImageURL }).appendTo('#defaultimage');

      if (product.options.length > 0) {
        $.each(product.options, function (idx, option) {
          /*appending the each option to a label*/
          $("" + "#" + option.OptionName + "").empty();
          if (option.values.length > 0) {
            /*Creating a select tag for the Retrieved options*/
            //$("" + "#" + options.OptionName + "").empty();                  
            $.each(option.values, function (idx, value) {                 
              alert(value.OptionValue);
 //             $("" + "#" + option.OptionName + "").append('<option value="' + value.OptionValue + '">' + value.OptionValue + '</option>');
              $("" + "#" + option.OptionName + "").children('option').hide();
  //            $("" + "#" + option.OptionName + "").children("option[text=" + value.OptionValue + "]").show();
              $("" + "#" + option.OptionName + "option[value='" + value.OptionValue + "']").show();
            });
          }
        })
      }
    });
  });
}    

in this case dropdowns are empty in the end

this is what the changes i made from the answer given

           if (product.options.length > 0) {
                    $.each(product.options, function (idx, option) {
                        /*appending the each option to a label*/

                        $("" + "#" + option.OptionName + " option").attr('not_required', 'true');
                        if (option.values.length > 0) {
                            /*Creating a select tag for the Retrieved options*/                                    
                            $.each(option.values, function (idx, value) {                             
                            alert(value.OptionValue);
                            $("" + "#" + option.OptionName + "option[value='" + this_value + "']").removeAttr('not_required');
                            $("" + "#" + option.OptionName + " option[not_required=true]").remove();

                            });

                        }

                    })
                }

the values are not removed

  • 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-12T22:50:28+00:00Added an answer on June 12, 2026 at 10:50 pm

    Start by setting an attribute in all options, e.g. “not_required”.

    $('#my_select_id option').attr('not_required','true');
    

    Then loop through your results, removing the attribute for each one as you find it.

    for(...) {
      $('option[value=' + this_value + ']').removeAttr('not_required');
    }
    

    Finally select all options which still have the attribute and remove (or hide) them.

    $('#my_select_id option[not_required=true]').remove();
    

    [Edit]

    You are removing the ‘unwanted’ options too soon. You need to wait until the loop finishes.

    This is my version of your edit above:

           if (product.options.length > 0) {
                    $.each(product.options, function (idx, option) {
                        $("" + "#" + option.OptionName + " option").attr('not_required', 'true');
                        if (option.values.length > 0) {
                            $.each(option.values, function (idx, value) {                             
                                alert(value.OptionValue);
                                $("#" + option.OptionName + " option[value='" + this_value + "']").removeAttr('not_required');
                            });
                        }
                    })
                    $("#" + option.OptionName + " option[not_required=true]").remove();
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create some cascading drop downs. I have my States loading via
I have some function where I need to pass a point datatype . somefunc(United
So I have some function that receives N random 2D points. Is there any
In JavaScript, if I have some function I can use the arguments object to
i have such function to solve some logic riddle iloczyny is list with such
I have a main function in javascript that is function a() { some code
I have a listener like this: $('.delete').click(function() { ...some stuff }); Also, on the
I made a Web service in which I have a function to count some
I have a function that will parse some data coming in. My problem is
After some recursive function I have an array: first iteration: Array ( [category_id] =>

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.