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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:39:39+00:00 2026-05-25T14:39:39+00:00

Im up to finding easy way to load to the HTML combo box dynamically

  • 0

Im up to finding easy way to load to the HTML combo box dynamically on changing another combo box i have a way but its really pain full and not a flexible code hard to maintain

For example I have 2 combo boxes country/provice when change the country according to country value province combobox value should change.

function getCo(cid){
    var countryVal=$('#cmbCountry').val();
    $.post("<?php echo url_for('country/ajaxloadcourse') ?>", //Ajax file
        { cid: cid },  // create an object will all values
        //function that is called when server returns a value.
        function(data) {
            var selectbox="<select name='province' id='province' class='formSelect' style='width: 150px;' tabindex='4' onchange='getCourseId(this.value,"+countryVal+")'>";
            selectbox = selectbox +"<option value=''><?php echo __('--Select--') ?></option>";
            $.each(data, function(key, value) {
                selectbox=selectbox +"<option value="+key+">"+value+"</option>";
            });
            selectbox=selectbox +"</select>";
            $('#provincelist').html(selectbox);
        },
        //How you want the data formated when it is returned from the server.
        "json"
    );
}

Is there any easy way to do this ,
Thanks

  • 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-25T14:39:40+00:00Added an answer on May 25, 2026 at 2:39 pm

    2 additional suggestions :

    1. You can put the “HTML” fragmen/DOM builder blocks in the server-side instead, so create a class/method to generating the DOM (Select box)(since almost all popular php framework have their HTML helper, or if you already used to some templating system, like Smarty), this may reduce your JS script for easier maintenance.

    2. Refactor your code. If you have some similar function/method, in your application, creating a common function is the best way to keep your code clean and maintanable. In this case, if you have more than one chaining combo-box method, it is a good idea to put some function like above into your own custom “plugin”, so you doesn’t need to write another identic function as above.

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

Sidebar

Related Questions

Is there an easy way of finding out the host name of a machine
UIImagePickerController is easy to use, but i'm all of a sudden finding it exasperating
Is there an easy way of finding the MAX number from the list where
What's an easy way of finding all the python modules from a particular package
Seems like this should be easy, but I'm not finding a simple configuration setting.
Is there a quick and easy way to grep through an array finding the
Is there an easy way of finding the neighbours (that is, the eight elements
I'm trying to use auto-generated forms in symfony, but I have troubles finding good
Is there an easy way or an html editor that can find all like-phases
Finding a good way to do this has stumped me for a while now:

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.