Link to home
Start Free TrialLog in
Avatar of Rakafkaven
Rakafkaven

asked on

Copy existing dropdown menu from parent to pop-up: IE hates it

I figure out one thing with this pop-up, something else stops working.  My main window spawns a pop-up calculator.  This calculator needs to have a drop-down select box identical to one on the main page.  I've tried two different methods that work brilliantly in Firefox and not at all in Internet Explorer.  No dropdown appears at all in the pop-up, and Explorer says the server "threw an exception" on the line below:

selSubMetal.options[i] = new Option(selMainMetal.options[i].text, selMainMetal.options[i].value);

I also tried using cloneNode prior to using the for loop: explorer behaved the same but the error then said "No such interface supported" on the "celMetSel.appendChild(selSubMetal);" line.   Firefox, again, worked without a hitch.

I added "alert (selMainMetal.length);" above the commented-out cloneNode attempt: selMainMetal is the variable representing the source select box, and the alert brings the correct value (19) in all attempts, which indicates that the source is coming in fine-- I just haven't figured out how to make the target inherit the options.

I'm starting to dislike Explorer.  Site is up at http://69.76.23.91/qfull.php , click the "Convert" button to see behavior.

function mCCaddElem() {
  var tblMCTable = winMetalCalc.document.getElementById('tblMCCalc');
  if (tblMCTable) {
    var intMCRow= tblMCTable.insertRow(0);
    var celMetSelLbl = intMCRow.insertCell(0);
    var lblMetSelLbl = winMetalCalc.document.createTextNode('Metal Type');
    celMetSelLbl.appendChild(lblMetSelLbl);
    var celMetSel = intMCRow.insertCell(1);
    var selMainMetal = winMetalCalc.opener.document.getElementById('selPPMet');
    alert (selMainMetal.length);
    //var selSubMetal = selMainMetal.cloneNode(true); //firefox only
    var selSubMetal = winMetalCalc.document.createElement('select');
    for (i=0; i < selMainMetal.length; i++) {
      selSubMetal.options[i] = new Option(selMainMetal.options[i].text, selMainMetal.options[i].value);
    }
    selSubMetal.value = selMainMetal.value;
    celMetSel.appendChild(selSubMetal);
   
  }
  else tId= setTimeout('mCCaddElem()',100);
}
ASKER CERTIFIED SOLUTION
Avatar of xlt77
xlt77

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rakafkaven
Rakafkaven

ASKER

Your code worked perfectly in IE, but broke in Firefox, creating a dropdown of apparently blank items (although the value was present, albeit invisible to the user).  Fortunately, using "oOption.text" instead of "oOption.innerText" works for both.  Standards compliance must be very scary, considering how much both IE and Firefox teams seem to fear it.

Thank you!