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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:17:36+00:00 2026-05-26T17:17:36+00:00

###########Update Here is the original code that worked in ie7 but not in 9.

  • 0

###########Update

Here is the original code that worked in ie7 but not in 9. I updated and thought both were ok.

if(max_ch>0){
var newDiv = $('<div>Room '+(i+1)+
    ' <select class="adu" name="data[Rate]['+r_id+']['+ro_id+
    '][adults][]"></select> adults. <select class="chi" name="data[Rate]['+r_id+
    ']['+ro_id+'][children][]"></select> children.</div>'
);
newDiv.attr("id","occupants"+i).appendTo(showdiv+' .rooms_adults');

var roomPrice = $('<input type="hidden" name="data[Rate]['+r_id+']['+ro_id+'][prices][]" value="'+room_bo+'" />');
roomPrice.attr("id","roomprice"+i).appendTo(showdiv+' .rooms_adults');

var num_opts = Number(max_ad) + 1,
    slc_adu = $(showdiv+' #occupants'+i+' select.adu');
for( ad=0; ad < num_opts; ad++){
    slc_adu.append("<option value=\"" + ad + "\">" + ad + "</option>");
}

var num_opts = Number(max_ch) + 1,
    slc_ch = $(showdiv+' #occupants'+i+' select.chi');
for( ch=0; ch < num_opts; ch++){
    slc_ch.append("<option value=\"" + ch + "\">" + ch + "</option>");
}

$(showdiv+' #occupants'+i+' select.adu').val('1');                  

}

I have some jquery to build drop-down boxes. I want the drop-downs to have the first value already selected in them. This happens on all browser except ie9.

It has a blank record as the first value.

            $('.rooms_select select' ).change(function(){

                var showdiv = '#div_'+$(this).attr('id');
                var r_id    = $(showdiv+' .rate_data').val();
                var ro_id   = $(showdiv+' .room_data').val();
                var min_ad  = $(showdiv+' .room_data').attr('minadults');                   
                var max_ad  = $(showdiv+' .room_data').attr('maxadults');
                var max_ch  = $(showdiv+' .room_data').attr('maxchildren');
                var total_price = $(showdiv+' .rate_data').attr('total_price');
                var price_quote = $(showdiv+' .rate_data').attr('rel');
                var rooms = $(this).val();
                var room_bo = 0;

                //$(showdiv+' .room_data').attr('numrooms', rooms);

                room_price = calc_rprice(showdiv,total_price,price_quote,rooms);
                // NEW THING
                room_bo = Number(room_price/rooms);

                $(showdiv).slideDown("slow");
                $(showdiv+' .rooms_adults').html('<span>Please select number of occupants.</span>');
                for( i=0; i < rooms; i++){

                    if(max_ch>0){
                        var newDiv = $('<div>Room '+(i+1)+' <select class="adu" name="data[Rate]['+r_id+']['+ro_id+'][adults][]"></select> adults. <select class="chi" name="data[Rate]['+r_id+']['+ro_id+'][children][]"></select> children.</div>');
                        newDiv.attr("id","occupants"+i).appendTo(showdiv+' .rooms_adults');

                        var roomPrice = $('<input type="hidden" name="data[Rate]['+r_id+']['+ro_id+'][prices][]" value="'+room_bo+'" />');
                        roomPrice.attr("id","roomprice"+i).appendTo(showdiv+' .rooms_adults');

                        var roomTotalPrice = $('<input type="hidden" name="data[Rate]['+r_id+']['+ro_id+'][roomTotalPrice][]" value="'+room_price+'" />');
                        roomTotalPrice.attr("id","roomTotalPrice"+i).appendTo(showdiv+' .rooms_adults');

                        var num_opts = Number(max_ad) + 1,
                            slc_adu = $(showdiv+' #occupants'+i+' select.adu');
                        for( ad=min_ad; ad < num_opts; ad++){
                            slc_adu.append("<option value=\"" + ad + "\">" + ad + "</option>");
                        }

                        var num_opts = Number(max_ch) + 1,
                            slc_ch = $(showdiv+' #occupants'+i+' select.chi');
                        for( ch=0; ch < num_opts; ch++){
                            slc_ch.append("<option value=\"" + ch + "\">" + ch + "</option>");
                        }

                        $(showdiv+' #occupants'+i+' select.adu').val('1');
                        $("select :first-child").each(function () {
                            $(this).attr("selected", true);
                        });

                    } else {
                        var newDiv = $('<div>Room '+(i+1)+' <select class="adu" name="data[Rate]['+r_id+']['+ro_id+'][adults][]"></select> adults.</div>');         
                        newDiv.attr("id","occupants"+i).appendTo(showdiv+' .rooms_adults');

                        var roomPrice = $('<input type="hidden" name="data[Rate]['+r_id+']['+ro_id+'][prices][]" value="'+room_bo+'" />');
                        roomPrice.attr("id","roomprice"+i).appendTo(showdiv+' .rooms_adults');

                        var roomTotalPrice = $('<input type="hidden" name="data[Rate]['+r_id+']['+ro_id+'][roomTotalPrice][]" value="'+room_price+'" />');
                        roomTotalPrice.attr("id","roomTotalPrice"+i).appendTo(showdiv+' .rooms_adults');

                        var num_opts = Number(max_ad) + 1,
                            slc_adu = $(showdiv+' #occupants'+i+' select.adu');
                        for( ad=min_ad; ad < num_opts; ad++){
                            slc_adu.append("<option value=\"" + ad + "\">" + ad + "</option>");
                        }
                        $(showdiv+' #occupants'+i+' select.adu').val('1');
                        $("select :first-child").each(function () {
                            $(this).attr("selected", true);
                        });


                    }

                calc_rprice(showdiv,total_price,price_quote,rooms);


            });
  • 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-26T17:17:37+00:00Added an answer on May 26, 2026 at 5:17 pm

    I’m loathe to facilitate the continued use of JS like this, but try something like:

    $("select :first-child").each(function () {
        $(this).attr("selected", true);
    });
    

    Edit: I want to reinforce that this model is an abuse of JavaScript. You may think that you’ve secured your website effectively, but I promise you that security on the web is an illusion, and using JavaScript like this makes your site an easy target.

    You really need to move far, far away from creating your HTML inside of JavaScript. If you absolutely have to have some form of asynchronous page modifications, you should really be using something like AJAX and securing your code elsewhere. You are giving away unneccessary information by exposing this kind of logic to the end-user.

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

Sidebar

Related Questions

UPDATE: So pretty much everyone here has told me that I just need to
Here is my chunk of code: var update_shipping_methods = function(methods) { $(methods).each( function(i) {
Replaces Question: Update multiple rows into SQL table Here's a Code Snippet to update
Update: This question was an epic failure, but here's the working solution. It's based
I'm trying to update an element in the XML document below: Here's the code:
UPDATE - A comprehensive comparison, updated as of February 2015, can be found here:
Update Luckily, the code that WebKit uses to make this control draws onto a
UPDATE: I have determined that the SQLClient code times out on the first call,
Update I summarized the question and its answers here My objective is to detect
Update In the wiki spirit of StackOverflow, here's an update: I spiked Joe White's

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.