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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:14:35+00:00 2026-06-07T06:14:35+00:00

i want to create select option dynamically. i have two array year and month.

  • 0

i want to create select option dynamically. i have two array “year” and “month”. when user select 2011 then its respective month should be display in next drop down. for example

if we select 2009 then next drop down option should be “dec”,”oct”,”feb’

<head>




<script type="text/javascript" src="jquery-1.7.2.js"></script>


<script type="text/javascript">

$(function (){

    $('#first').change(function(){

    var year= new Array('2011','2010','2009');
    var month= new Array('jan_feb_march','jan_march_april','dec_oct_feb');

    var yearVal= $('#first option:selected').text();


for(i=0; i<year.length;i++){


    if(year[i]==yearVal){

    var months=month[i]


}


}



    var y= months.split('_');

for (z=0;z<y.length;z++){


$('#second').append("<option>'"+y[z]+"'</option>")  

    }



    })
})


</script>


</head>

<body>


<div class="menu">
<select id="first">
<option>select</option>
<option>2011</option>
<option>2010</option>
<option>2009</option>

</select>
<select id="second"></select>

</div>


</body>
  • 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-07T06:14:36+00:00Added an answer on June 7, 2026 at 6:14 am

    See this DEMO:

    http://jsfiddle.net/rathoreahsan/vMuev/

    JQUERY:

    var categories = {
        "None":[{value:'3', text:'No cataegory selected'}],
        "2011":[{value:'1', text:'jan_feb_march'}],
        "2010":[{value:'2', text:'jan_march_april'}],
        "2009":[{value:'3', text:'dec_oct_feb'}]
    };
    
    function selectchange(){
        var select = $('[name=items]');
        select.empty();
        $.each(categories[$(':selected', this).text()], function(){
            select.append('<option value="'+this.value+'">'+this.text+'</option>');
        });
    }
    
    $(function(){
        $('[name=category]').on('change', selectchange);
    });
    

    Hope this will be useful 🙂

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

Sidebar

Related Questions

I have a select box that gets generated dynamically. I want to allow users
Suppose I want to create a select box in PHP. $months = array ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
I have installed eclipse Helios and want to create a plugin project. I select
I create select element dynamically using jquery, and I want to make action when
I'm not great with CSS, but I want to create two select lists with
I want to create the following T-SQL statement: SELECT SUM (sa.Amount) as 'SumAmount', SUM(sa.Cost)
I want to create JSF table which has select all button and check box
How to select a same database? I want to create a table from already
I am trying to populate a select list with time. I want to create
I want to write a stored procedure like this Create Proc dbo.GetApplicantsByIDs as Select

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.