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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:54:05+00:00 2026-05-23T18:54:05+00:00

I create select element dynamically using jquery, and I want to make action when

  • 0

I create select element dynamically using jquery, and I want to make action when change event occur. that is, I want to fill another select box when user choose option from the previous select box.
the code did not work because the first select box created (completely) dynamically (not just filled dynamically). I tried to make static select box and dynamically filling it and when user choose option from this combo box, I fill another combo box.this code work properly.
but in my case, I have to create the select element dynamically. I know the problem but I do not know how to fix it.
I wrote this code:

$(document).ready(function(){

$("a.package").click(function(){

        var id = $(this).attr('id');
        var parameters = {"privPackage":id};
        $.getJSON("InquirerManagmentServlet", parameters, function (result){
            //alert('get param');
            var data = result[0];
            var cities = result[1];
            var semester = result[2];
            var college = result[3];

            for (var i = 0; i < data.length; i++) {
                var privNo = data[i]["privNo"];
                var privName;
                var input;
                if (privNo == 302){
                    if(college !== null && college.length){
                        input = $('<select name = "'+privNo+'" id ="collegeEName">');
                        $('>option',input).remove();
                        input.append($('<option >').val(0).text("choose .."));
                        for(var j=0; j<college.length; j++){
                            var option = $('<option />');
                            option.attr("value",college[j]["collegeNo"]);
                            option.text(college[j]["collegeEName"]);
                            input.append(option);
                         }
                    }
                } else if(privNo == 308){
                   //
                }
                $("div#InfoToValidate").append(input);
            }
        });
});

// fill second combo boxes
$("select").change(function(){
    alert("heey");
    var id = $(this).attr('id');
    if(id == "collegeEName"){
        var collegeNo = $(this).val();  // .text();
        var parameter = {
            "collegeNo":collegeNo
        };
        $.getJSON("InquirerManagmentServlet", parameter, function (departments){
            //var neighborhoods = result
            var idSecond = "departmentEName";
            $('>option',$("select#"+idSecond+"")).remove();
            $("select#"+idSecond+"").append($('<option/>').text(""));
            for(var j=0; j<departments.length; j++){
                $("select#"+idSecond+"").append($('<option value = "'+departments[j]["departmentNo"]+'"/>').text(departments[j]["departmentEName"]));
            }
        });
    }
    // the rest of code
});

});

Could someone help me please?

  • 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-23T18:54:06+00:00Added an answer on May 23, 2026 at 6:54 pm

    Because you are creating your select element after the DOM has already loaded, you need to use a future-prove binding method such as live or delegate:

    Change

    $("select").change(function(){
    

    to

    $("select").live('change',function(){
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a <select> element which I need to track using change(). jQuery('.dropdown').change(function(){ yada,
I want to create a form element that gonna output like this select date:
I want to create a JavaScript/jQuery/jQuery UI drop-down select for element ordering in my
Is it possible to create a MySQL select statement that uses an expression as
I want to create a SQL Select to do a unit test in MS
I'm not great with CSS, but I want to create two select lists with
On my aspx page I dynamically create html controls on client side using javascript.
My create view code like this create VIEW [dbo].[vw_test] AS SELECT 'B' AS rtype,
Is a select * from myView faster than the query itself to create the
I know the statement: create table xyz_new as select * from xyz; Which copies

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.