Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 411
  • Last Modified:

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);
}
0
Rakafkaven
Asked:
Rakafkaven
1 Solution
 
xlt77Commented:
Hi  Rakafkaven:

Try this code about mCCadElem() function.

-----------------------------------------------------------------------------------------

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++) {
        var oOption = winMetalCalc.document.createElement("OPTION");
          alert(selSubMetal.options.length);
            selSubMetal.options.add(oOption);
            oOption.innerText = selMainMetal.options[i].text;
            oOption.value = selMainMetal.options[i].value;
    }
    selSubMetal.value = selMainMetal.value;
    celMetSel.appendChild(selSubMetal);
   
  }
  else tId= setTimeout('mCCaddElem()',100);
}
0
 
RakafkavenAuthor Commented:
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!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now