By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,966 Members | 1,913 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,966 IT Pros & Developers. It's quick & easy.

Problem with javascript cascade comboboxes

P: 5

I am having a problem with to linked comboxes in IE7. Here is my problem that is ONLY ocurring in IE7: I have javascripts functions to populate the second of 2 comboxes given the selected option on the first one; the scripts look to be ok since they work perfectly on firefox 3.08 and also on IE6 and IE8; I have inspected the generated combobox options code using firebug extension on firefox and they are ok; on IE7 the options for the second combo are being populated without errors, but it is crashing after I select an option on the first combobox that only have 1 option asociated in the second combobox and then try to open the second combobox; IE7 crash and is displaying a messages that reads "IE7 has stop responding bla bla....".

Just in case you do not fully understand: my problem only ocurrs if there is only one option on the second combobox, if there are 2+ the problem does not ocurr.

The first combobox has the function setDynaList attached to the OnChange event..

Here are my javascripts functions:

Expand|Select|Wrap|Line Numbers
  1. function setDynaList(cbx1, cbx2, arr, addFirstOption){
  2.     var oList1     = document.getElementById(cbx1);
  3.     var oList2     = document.getElementById(cbx2);
  5.     clearDynaList(oList2);
  7.     if (oList1.selectedIndex == -1){
  8.         oList1.selectedIndex = 0;
  9.     }
  11.     populateDynaList(oList2, oList1[oList1.selectedIndex].value, arr, addFirstOption);
  12.     return true;
  13. }
  15. function clearDynaList(oList){
  16.     oList.selectedIndex = -1;
  17.     for (var i = oList.options.length; i >= 0; i--){
  18.         oList.options[i] = null;
  19.     }    
  20.     oList.selectedIndex = -1;
  21. }
  23. function populateDynaList(oList, nIndex, aArray, addFirstOption){
  24.     if (addFirstOption == true) {
  25.         var aOption;
  26.         aOption = document.createElement("OPTION");
  27.         aOption.value = '';
  28.         aOption.text = '- select -';     
  29.         oList.options.add(aOption);
  30.     }
  32.     for (var i = 0; i < aArray.length; i= i + 3){
  33.         if (aArray[i] == nIndex){
  34.             aOption = document.createElement("OPTION"); 
  35.             aOption.value = aArray[i + 1];
  36.             aOption.text = aArray[i + 2]; 
  37.             oList.options.add(aOption);
  38.         }
  39.     }
  41.     if (oList.options.length > 0) {
  42.         oList.selectedIndex = 0;
  43.     } else {
  44.         oList.selectedIndex = -1;
  45.     }
  46. }
  48. function setDefaListbyValue(sList, sDefault){
  49.     oList = document.getElementById(sList);
  50.     var found = false;
  51.     for (var i = 0; ((i < oList.options.length) && (!found)) ; i++){
  52.         if (oList.options[i].value == sDefault){
  53.             oList.options[i].setAttribute('selected', 'true');
  54.             oList.options[i].selected = true;
  55.             found = true;
  56.         }
  57.     }    
  58. }
  60. function setDefaListbyText(sList, sDefault){
  61.     oList = document.getElementById(sList);
  62.     var found = false;
  63.     for (var i = 0; ((i < oList.options.length) && (!found)) ; i++){
  64.         if (oList.options[i].text == sDefault){
  65.             oList.options[i].setAttribute('selected', 'true');
  66.             oList.options[i].selected = true;
  67.             found = true;
  68.         }
  69.     }    
  70. }
  72. function setupDefaList(sList, sDefault, nIndex, aArray, addFirstOption){
  73.     oList = document.getElementById(sList);
  74.     clearDynaList(oList);
  75.     populateDynaList(oList, nIndex, aArray, addFirstOption);
  76.     setDefaListbyText(sList, sDefault);
  77. }
and here is the array that dinamically I and wrting to the page reading from the database:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. //<![CDATA[
  3. var MyItemsArray =  new Array('6','16687','Furniture for care, play and learning', '6','16688','Furnishings for relaxation', '6','16689','Room arrangement', '6','16690','Space for privacy', '6','16691','Child-related display', '6','16692','Space for gross motor', '6','16693','Gross motor equipment', '7','16694','Meals/snacks', '7','16695','Nap/rest', '7','16696','Toileting/diapering', '7','16697','Health practices', '7','16698','Safety practices', '8','16699','Books and pictures', '9','16700','Art', '9','16701','Music / movement', '9','16702','Blocks', '9','16703','Sand / water', '9','16704','Dramatic play', '9','16705','Nature / science', '9','16706','Use of TV, video, and/or computers', '9','16707','Promoting acceptance of diversity', '10','16708','General supervision of children', '11','16709','Schedule', '11','16710','Free play', '11','16711','Group time', '11','16712','Provisions for children with disabilities');
  4. //]]>
  5. </script>
in the array every 3 elements the first element is the parent id(the selected value on the first combobox), the second is the value and the third is the name for the option on the second combobox.

any Idea?
Apr 2 '09 #1
Share this Question
Share on Google+
6 Replies

Expert Mod 15k+
P: 16,027
I quickly tested your code with two simple select elements and there were no problems in IE7. Post your HTML code. Do you have any other code, e.g. an onchange in the second combo?
Apr 2 '09 #2

P: 5
My page is a complex one that uses a database as backend; it is a .net page that uses framework 2.0 and have security , ...., but I can asure you that I have tested this code from many computers and IE7 fails with no exceptions whenever you try to open the second combo and this combo has only one option. I used this code when I was working for a company in Cuba 3 years ago; not being convinced about what was ocurring in my new page I visited one of the pages that uses this code in the cuban website and the error is present there too. It looks like it is a bug in IE7. Here is the URL and the instructions:

the link is: and there go to a box that you will see at the right of the page; it is the one that reads "Search Cuba Hotels"; the destination combo is the parent and the hotel's combo is the child combobox; select "Centro Havana" destination in the parent (this destination does not have hotels and by this reason the child combo only gets 1 option: - any hotel - ), select another destination like Havana that has a lot of hotels and then go back and select "Centro Havana" again; try to open the child combo to crash your IE7. I think that in my original post I did not specified that the error only ocurrs the second time you open the child combo when it have only one option.
Apr 2 '09 #3

Expert Mod 15k+
P: 16,027
I tried to crash my IE7 unsuccessfully! For good measure, I even tried it a third time. Perhaps you need to re-install your version of IE7. Is it a stand-alone version or the original?
Apr 2 '09 #4

P: 5
You are right acoder; it looks like the problem is related to this specific IE7 installation from where I have been testing(I tested from another pc and the error does not ocurr); the one with the problem is a Dell modified version since this computer is a Dell. I would never imagine that a modified version can introduce problems like this one.
May I install the original IE7 version above this one? I am asking because I think it is not possible to remove IE7 from vista and then install it again...and for now I need to have IE7 in this pc for my development testings .
Apr 2 '09 #5

P: 5
if the solution is to reinstall IE7 on vista; from where can I download the installer? since IE7 comes preinstalled on vista I cannot find the installer for vista anywhere on the MS website...
Apr 3 '09 #6

Expert Mod 15k+
P: 16,027
You could try resetting IE as described here.
Apr 3 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.