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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:04:23+00:00 2026-05-31T16:04:23+00:00

I am trying to populate a <select> element via Ajax. It works great in

  • 0

I am trying to populate a <select> element via Ajax. It works great in FF, but I get an unknown runtime error in IE.

HTML:

<select id="emp_select" name="emp_select">
    <option value=" ">Please enter a store</option> 
</select>

Javascript:

$("#store").blur(function() {
    populateDropdowns();
});

...

function populateDropdowns() {
        var store = $("#store").val();

        if (store.length != 4) {
            alert("Store # must be 4 digits!");
            $("#store").focus();
            return false;
        }

        var xhrJSON = new XMLHttpRequest();
        var xhrEmpSelect = new XMLHttpRequest();
        var xhrMgrSelect = new XMLHttpRequest();

        var jsonDone = false;
        var empSelectDone = false;
        var mgrSelectDone = false;

        $("#processing-dialog").dialog({
                width: 300,
                height: 150
        });

        xhrJSON.onreadystatechange = function() {
            if (xhrJSON.readyState == 4) {
                if (xhrJSON.status == 200) {
                    var js = document.createElement('script');
                    js.type = 'text/javascript';

                    js.innerHTML = xhrJSON.responseText;
                    var scr = document.getElementsByTagName('script')[1];
                    scr.parentNode.insertBefore(js,scr);

                    jsonDone = true;
                    if (jsonDone && empSelectDone && mgrSelectDone) {
                        $("#processing-dialog").dialog("close");
                        $("#processing-dialog").dialog("destroy");
                        return true;
                    }
                } else {
                    return false;
                }
            }
        }

        xhrEmpSelect.onreadystatechange = function() {
            if (xhrEmpSelect.readyState == 4) {
                if (xhrEmpSelect.status == 200) {
                    $("#emp_select").html(xhrEmpSelect.responseText);
                    empSelectDone = true;
                    if (jsonDone && empSelectDone && mgrSelectDone) {
                        $("#processing-dialog").dialog("close");
                        $("#processing-dialog").dialog("destroy");
                        return true;
                    }
                } else {
                    return false;
                }
            }
        }

        xhrMgrSelect.onreadystatechange = function() {
            if (xhrMgrSelect.readyState == 4) {
                if (xhrMgrSelect.status == 200) {
                    $("#mgr_select").html(xhrMgrSelect.responseText);
                    mgrSelectDone = true;
                    if (jsonDone && empSelectDone && mgrSelectDone) {
                        $("#processing-dialog").dialog("close");
                        $("#processing-dialog").dialog("destroy");
                        return true;
                    }
                } else {
                    return false;
                }
            }
        }

        var url = "ajax.cgi";

        var JSONdata = "action=generateJSON&store=" + store;
        var EmpSelectData = "action=generateEmpSelect&store=" + store;
        var MgrSelectData = "action=generateMgrSelect&store=" + store;

        xhrJSON.open("POST",url);
        xhrJSON.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xhrJSON.send(JSONdata);

        xhrEmpSelect.open("POST",url);
        xhrEmpSelect.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xhrEmpSelect.send(EmpSelectData);

        xhrMgrSelect.open("POST",url);
        xhrMgrSelect.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xhrMgrSelect.send(MgrSelectData);
    }

The blur handler calls a function to populate (all) the different select elements, plus a JavaScript object that holds an associative array of all the employees to match up a name with an employee id that is returned as the values of the options in both select elements.

XHR Text returned (for xhrJSON, content-type=application/json):

var empArray = new Array({ id:"12345678", title:"The Title", code:"C123", name:"John Doe"},...);

XHR Text returned for (xhrEmpSelect, content-type=text/html):

<option value=" ">Select One</option>
<option value="John Doe">John Doe</option>
<option value="Joe Blow">Joe Blow</option>
...
<option value="other">Other...</option>
</select>

Similar text is returned for xhrMgrSelect, content-type=text/html

So in FF everything works great, the JS Object comes across and is inserted into the DOM and both <select> elements are populated as well. BUT in IE, I get an unknown runtime error in the xhrJSON.onreadystatechange handler where I try and set the js.innerHTML to the xhrJSON.responseText.

What am I doing wrong?

  • 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-31T16:04:25+00:00Added an answer on May 31, 2026 at 4:04 pm

    Try using js.text = xhrJSON.responseText; instead of innerHTML. I believe the issue you are encountering has to do with the fact that you can’t insert HTML into a <script> block.

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

Sidebar

Related Questions

I am trying to populate a select list with AJAX as follows: HTML: <table>
I'm trying to populate an element after an ajax call is made, but I'm
I am trying to populate a jqGrid search form using a SELECT element. In
I'm trying to populate a select element with firstname and lastname values from a
What I am trying to do is populate data in a select element. I'm
I am trying to populate a select list with time. I want to create
Hello I am trying to build a multi select to populate a many-to-many join
I trying to populate the dropdown list when page was loaded.But it is not
I am trying to populate a ListView ....but I cant add 2 string values
I'm trying to get a filtering select work with a Dojo enabled form using

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.