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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:49:24+00:00 2026-06-01T12:49:24+00:00

I have a drop down list which is dynamically generated using ajax on page

  • 0

I have a drop down list which is dynamically generated using ajax on page load.
On the other hand I have a php variable which contains the value to be selected by default.
However, when Iam trying to do this it isn’t selecting the value. Following is code:

HTML & PHP

<h1>Venue: Edit</h1>
<a href="/venue"><< Back to Venue List</a>
<br />
<form method="post" id="venueEdit" action="<?php echo URL;?>venue/editSave/<?php echo $this->venue['id']; ?>">
    <fieldset>
            <p>
                <label for="cvenue" class="main">Venue</label>
                <input id="cvenue" class="required" type="text" name="venue" value="<?php echo $this->venue['name']; ?>" />
            </p>
            <p>
                <label for="ccity" class="main">City</label>
                <input id="ccity" class="required" type="text" name="city" value="<?php echo $this->venue['city']; ?>" />
            </p>
            <p>
                <label for="ccountry" class="main">Country</label>
                    <select id="ccountry" class="required" name="country">
                        <option value="">-- Select Country --</option>
                    </select>

            </p>
            <p>
                <label class="main">&nbsp;</label><input type="submit" value="Save" />
            </p>
        </fieldset>   
</form>

JS:

function populateCountryDropDown(url){
    $.get(url, function(o) {
        for(var i = 0; i < o.length; i++){
            $('select[name="country"]').append('<option value="' + o[i].id + '">' + o[i].name + "</option>");
        }
    }, 'json');
}

$(document).ready(function(){
        populateCountryDropDown('<?php echo URL; ?>' + 'country/xhrGetCountryList');
        $('select[name="country"]').val('<?php echo $this->venue['countryid']; ?>');
        $("#venueEdit").validate();
    });

I tried to alert the php value and it’s ok but if I alert the select option value it’s always null as at that point it’s still populating the drop down list. I don’t know how to solve this. Would appreciate your guys help? 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-06-01T12:49:25+00:00Added an answer on June 1, 2026 at 12:49 pm

    You need to move your code to set the value into the callback, to trigger the value being set after the AJAX call fired off by $.get() returns.

    function populateCountryDropDown(url){
        $.get(url, function(o) {
            for(var i = 0; i < o.length; i++){
                $('select[name="country"]').append('<option value="' + o[i].id + '">' + o[i].name + "</option>");
            }
            $('select[name="country"]').val('<?php echo $this->venue['countryid']; ?>');
            $("#venueEdit").validate();
        }, 'json');
    }
    
    $(document).ready(function(){
            populateCountryDropDown('<?php echo URL; ?>' + 'country/xhrGetCountryList');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a drop down list which is populated dynamically from database table i.e
I have a drop-down list which causes a text-area to populate with different text
Basically I have a drop down list which is populated with text and values
I've got a page which will have about ten drop down lists which are
I have a drop-down list containing classifications of currencies which can be instantiated as
I have a drop down list with two values (for now..) with other elements
I have a page that postbacks on a dropdown list selection (using AJAX update
I have a datatable which has been dynamically generated from FoxPro tables using a
I have a drop-down list which gathers data from the database and a textbox
I have a drop down list (ddlFilterBuildings) which contains a list of buildings to

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.