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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:47:35+00:00 2026-05-24T02:47:35+00:00

I have a little script that generates a select field and selects the appropriate

  • 0

I have a little script that generates a select field and selects the appropriate option when it’s generated. It looks a bit like this:

options.each(function (option) {
    var optionString = "<option id='" + option.id + "' value='" + option.value + "'>" + option.text + "</option>";
    $('selectField').insert(optionString);
    if(option.selected) {
        toBeSelected = option.id;
    }
});
$(toBeSelected).setAttribute('selected','selected');

Now the above script works fine in Chrome and Firefox, but in IE it will always select the last element in the list. so say I was generating a list of options ['a','b','c','d'], ‘d’ would always be selected.

Does anybody have an idea what could be causing this?

UPDATE:
Okay, I found a solution to this, and it involved replacing the ‘insert’ with generating the option nodes manually, a bit like the following:

var newOption = document.createElement('option');
newOption.setAttribute('value',option.value);
newOption.innerHTML = option.text;
if(option.selected) {
    newOption.selected = true;
}

$('selectField').appendChild(newOption);

I’m guessing the issue lied with how the prototype insert() works, although I’m just glad the problem is solved.

I’ll reformat this as an answer once the 8 hours are up to answer my own question.

Thankyou all for your input in 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-05-24T02:47:35+00:00Added an answer on May 24, 2026 at 2:47 am

    Okay, I found a solution to this, and it involved replacing the ‘insert’ with generating the option nodes manually, a bit like the following:

    var newOption = document.createElement('option');
    newOption.setAttribute('value',option.value);
    newOption.innerHTML = option.text;
    if(option.selected) {
        newOption.selected = true;
    }
    
    $('selectField').appendChild(newOption);
    

    I’m guessing the issue lied with how the prototype insert() works, although I’m just glad the problem is solved.

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

Sidebar

Related Questions

I have a django template that looks like this: <head> <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js type=text/javascript></script> <script
I have wrote this little script which generates a nice random password. The problem
I have a little python script that pulls emails from a POP mail address
I have a little Perl script (On Windows) that checks some files for me
I have this little script to toggle a contact form when a button is
This is a little tricky so bear with me: I have a PHP script
So I have this php script that output an html table with data about
I have a little script that replace some text, that come from a xml
I have this line in a useful Bash script that I haven't managed to
I have a little script that compiles a markdown file into html, and inserts

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.