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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:58:24+00:00 2026-05-24T00:58:24+00:00

I have a element in my form. <select name=states disabled=disabled size=10 id=select-states><optgroup label=Choose State

  • 0

I have a element in my form.

<select name="states" disabled="disabled" size="10" id="select-states"><optgroup label="Choose State &raquo;&nbsp;">Choose State</optgroup></select>

I would like to replace the above select element with the new <select> i received from AJAX.

$.ajax({
    type: 'POST',
    url:  'process.php',
    data: 'countryId='+countryId,
    success: function(msg){
        if(msg == 0) {
            //Query returned empty.
        } else {
            //Query Has values.
            $('#select-states').html(msg);
        }
    }
});

for example the above Ajax Request gives me back the following HTML.

<select name="states" size="10" id="select-states">
    <optgroup label="Choose State">Choose State</optgroup>
    <option value="36">First State</option>
    <option value="37">Second State</option>
    <option value="38">Third State</option>
    <option value="39">Fourth State</option>
</select>

Syntax $('#select-states').html(msg); does not seems to be replacing the content correctly in <select> element. however if i replace it with div it works properly. which is the correct syntax for replacing the <select> element

  • 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-24T00:58:25+00:00Added an answer on May 24, 2026 at 12:58 am

    You were close. Just change this line:

    $('#select-states').html(msg);
    

    To:

    $('#select-states').replaceWith(msg);
    

    The way you have it right now it will insert your new select into the old one and you’ll get some weird html with two elements with the same id and a select directly inside another, like:

    <select name="states" disabled="disabled" size="10" id="select-states">
        <select name="states" size="10" id="select-states">
            <optgroup label="Choose State">Choose State</optgroup>
            <option value="36">First State</option>
            <option value="37">Second State</option>
            <option value="38">Third State</option>
            <option value="39">Fourth State</option>
        </select>
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form element defined as: <div class=field> <div class=name> <label for=User_LastName> Last
I have a select form element with 5 options. If option 2 is selected
Okay so say I have a form element like this: HTML: <div class=form-item> <label>Current
I have a form, like so: <form action= method=post> <select name=pageType> <option value=main>Main Page</option>
I have a SELECT element in a form which I'm populating using AJAX when
I have html like this: <form action= id=emailFillOutForm> <div class=txt-fld> <label for=repName>Rep. Name</label> <input
I have a form in which i use javascript to set the select element
I have a form with 3 select elements. Each one, by default, has option
I have a Form element: $Form=new Zend_Form; $Form->setAction($this->view->url(array('controller'=>'auth','action'=>'create'),null,true)) ->setMethod('post') ->setAttrib('id','auth-form') ->removeAttrib('enctype'); As can be
I have a webpage with a form element and a popup window (opened by

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.