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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:03:21+00:00 2026-05-16T05:03:21+00:00

I have a select list with numbers in it. These numbers go from 0

  • 0

I have a select list with numbers in it. These numbers go from 0 to 30. I want to hide numbers based on the number of days apart from the current date and the date the user set.

So if today is July 28th 2010 and they Set July 29th 2010 it should only show “0”.

If it was July 28th 2010 and they set September 20th 2010 it should show 0 to 30.

So I have this

  var selectedDate = new Date($('#TextBox').val().replace(/\/(\d\d)$/, "/20$1"));
    var currentDate = new Date();

    var month = currentDate.getMonth() + 1
    var day = currentDate.getDate()
    var year = currentDate.getFullYear()

    currentDate = new Date(month + "/" + day + "/" + year);


    if (isNaN(selectedDate) == false)
    {
        $('#selectList').find('select').attr('disabled', '');

        var diffDays = parseInt((selectedDate  - currentDate) / (1000 * 60 * 60 * 24));

        var Options = $('#selectList').find('option');

        jQuery.each(Options, function (i, value)
        {
            var currentValue = $(this).val();
            if (currentValue == -1)
            {
                // equal to continue;
                return true;
            }
            else if (currentValue >= diffDays)
            {
                $(this).hide();
            }
            else
            {
                $(this).show();
            }
        });
    }

This code happens on change of the textbox of where the user would select a date.

This works fine in FireFox but does not work in any other browser. I don’t know why. No errors are shown in any of the browsers.

  • 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-05-16T05:03:21+00:00Added an answer on May 16, 2026 at 5:03 am

    You simply can’t hide/show <option> elements like this cross-browser, you need to either have a backup/hidden <select> and copy only the <option> elements you want each time, or just disable the <option> elements you don’t want to be selectable, this will however leave them visible.

    The cloning bit would look something like this:

    var hiddenSelect = $("#selectList").find('select').clone();
    var selectedDate = new Date($('#TextBox').val().replace(/\/(\d\d)$/, "/20$1"));
    var currentDate = new Date();
    
    var month = currentDate.getMonth() + 1
    var day = currentDate.getDate()
    var year = currentDate.getFullYear()
    
    currentDate = new Date(month + "/" + day + "/" + year);
    
    
    if (isNaN(selectedDate) == false) {
        $('#selectList').find('select').attr('disabled', '');
        var diffDays = parseInt((selectedDate  - currentDate) / (1000 * 60 * 60 * 24));
    
        var select = $('#selectList').find('select').empty();
        hiddenSelect.children().each(function(i, value) {
            if (value == -1) {
                return true;
            }
            else if (currentValue < diffDays) {
                $(this).clone().appendTo(select);
            }      
        });
    }
    

    We’re just keeping a cloned copy of the original in a variable called hiddenSelect, emptying (via .empty()) out the options on the visible one in the UI, and looping through/cloning the options you want to see back into that visible select.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following select list from which the user can select multiple values.
I have a select list. I want to append a new item in italic
I have a select list which is being populated using the values from a
I have a html form which have a select list box from which you
I have a multi-select list box. I want to be able to select a
I have scenario where i want the invoice numbers from two tables in csv
I have a select list, where you can choose multiple cities - When choosing
I have a select list I've created in a form alter, however, when I
I have a SELECT LIST MENU containing products and on this menu i use
I have a main select list of courses which drives various things on a

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.