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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:20:20+00:00 2026-06-04T01:20:20+00:00

I have a multiple selectbox with cities to a corresponded country which enable users

  • 0

I have a multiple selectbox with cities to a corresponded country which enable users to select multiple cities. In the form filling process, user has to select the country first, and the cities need to changed in the multiple selectbox accordingly. Here below my country select box and cities multiple SB.

<select name="country" id="country" onchange="ajax_change(this.value)">
    <option value="">--Select Country--</option>
    <? echo $countryList;?>
</select>

and here is the multiple selectbox

<select multiple="multiple" name="cities[]" id="cities[]" style="height:150px; width:300px;">
    <option value="">-- Select City --</option> 
</select>

This is the ajax code which is returning successfully the cities list.

<script type="text/javascript">
    function ajax_change(val)
    {

        jQuery.post(
            '<?=WEB_ROOT?>index.php?rt=admin/airport/ajax',
            {
                val:val,
                type:'get_cities'
            },
            function(data){
                $('#cities[]').val(data);
            }
        );
    }
</script>

But $('#cities[]').val(data) is not working. Can you please anyone help me on this.

  • 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-04T01:20:22+00:00Added an answer on June 4, 2026 at 1:20 am

    You want to use the $.each function to loop over the return data (I am assuming it is JSON) and then append newly created items to your list.

    Give this a try:

    HTML

    <select id='select' />​
    

    Javascript

    var data = {
        'name1':'value1',
        'name2':'value2'
    };
    
    $.each(data, function(key, value) {
        $('#select').append($("<option/>").text(key).val(value));
    });
    

    The above in jsfiddle: jsfiddle

    You also want to remove the square brackets from the ID.

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

Sidebar

Related Questions

I have a form where a user can add multiple select boxes for multiple
I have a multiple select box which appears when I click the link 'Share'.
I have used Multiple select Box in edit form, displaying previously selected items in
Using Wordpress I have created a multiple select box so that users can select
I have a javascript function below to move from select multiple box A which
I have a select field in a form that allows you to select multiple
I have a form with a select box that allows multiple options. After a
I have a form with a table that has two input boxes, a select
I have the following multi select box in a HTML form: <select multiple=multiple name=fruits>
I have an edit form that contains multiple select fields with selected options. Is

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.