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

  • Home
  • SEARCH
  • 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 3302614
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:52:13+00:00 2026-05-17T20:52:13+00:00

I have 2 select inputs and I filling them with an array of years.

  • 0

I have 2 select inputs and I filling them with an array of years. After that I want to set currentYear the selected value for every Select. I hacve this code but only works with first Select I don’t understand why.

Everything works great with jQuery 1.4.3, 1.4.2 fails :_(

I’m trying this without success 🙁 only fisrt has selected value OK. Can be a problem in versions? IE6, asp.net 2.0, jquery 1.4.2. For example, "$(sinceComboSelector).val(currentYear);" doesn’t work i have to do a "$(‘#cmbAnyDesde option[value=’ + currentYear + ‘]’).attr(‘selected’, ‘selected’);" 🙁

Code updated:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Tests.aspx.cs" Inherits="Tests" %>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="../JAVASCRIPT/jquery-1.4.2.min.js" type="text/javascript"></script>
    </head>
    <body>
        <script type="text/javascript">
            $(document).ready(function() {
                loadYears();
            });
            var loadYears = function() {
                var currentYear = new Date().getFullYear(),
                    years = [],
                    firstYear = currentYear - 7,
                    lastYear = currentYear + 3,
                    sinceComboSelector = "#cmbAnyDesde",
                    toComboSelector = "#cmbAnyHasta",
                    i;
    
                for (i = firstYear; i <= lastYear; i++) {
                    years.push(i);
                }
    
                $(sinceComboSelector).find('option').remove();
    
                $(toComboSelector).find('option').remove();
    
                $.each(years, function(key, value) {
                    $(sinceComboSelector)
                      .append($("<option></option>")
                      .attr("value", value)
                      .text(value));
    
                    $(toComboSelector)
                      .append($("<option></option>")
                      .attr("value", value)
                      .text(value)); ;
                });
    
    //            $(sinceComboSelector).val(currentYear);
    //            $(toComboSelector).val(currentYear);
                $('#cmbAnyDesde option[value=' + currentYear + ']').attr('selected', 'selected');            
                $('#cmbAnyHasta option[value=' + currentYear + ']').attr('selected', 'selected');
            }; 
        </script>
        <form id="form1" runat="server">
        <div>
            <select id="cmbAnyDesde" style="width:70px"></select>
            <select id="cmbAnyHasta" style="width:70px"></select>
        </div>
        </form>
    </body>
</html>
  • 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-17T20:52:14+00:00Added an answer on May 17, 2026 at 8:52 pm

    I tested here, with this code above, and works:

    $(document).ready(function (){
    
      loadYears();
    
    });
    
    var loadYears = function () {
      var currentYear = new Date().getFullYear(),
        years = [],
        firstYear = currentYear - 7,
        lastYear = currentYear + 3,
        sinceComboSelector = "#cmbAnyDesde",
        toComboSelector = "#cmbAnyHasta",
        i;
    
      for (i = firstYear; i <= lastYear; i++){
        years.push(i);
      }
    
      $(sinceComboSelector).find('option').remove();
    
      $(toComboSelector).find('option').remove();
    
      $.each(years, function(key, value) {
        $(sinceComboSelector)
          .append($("<option></option>")
          .attr("value", value)
          .text(value));
    
        $(toComboSelector)
          .append($("<option></option>")
          .attr("value", value)
          .text(value)); ;
      });
    
      $(sinceComboSelector).val(currentYear);
      $(toComboSelector).val(currentYear);
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Tab1, Tab2 and Tab3... All tabs have inputs that are validated ...
I have the following HTML: <input id=outer type=file onchange=console.log('No.');> <input id=inner type=file onchange=console.log('Yes!'); />
I want to make a primitive movie player in Labview. I want the user
My issue is trying to align my radio buttons so that they appear to
I am using SqlDataSource to pull in information from a table such that only
I often wish to see the internal representation of Mathematica 's graphical objects not
I know it's probably jQuery, I just can't figure out how to do it.
I believe this has been a bug/problem in SQL 2000/2005 ... If my results
I'm using C# with .NET 4 (though as per company policy, we never use
Here is my sample code: public static class MySqlHelper { private static string constring

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.