Web Analytics Made Easy -
StatCounter Creating dynamic list from child window - works for Netscape only - CodingForum

Announcement

Collapse
No announcement yet.

Creating dynamic list from child window - works for Netscape only

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating dynamic list from child window - works for Netscape only

    I have a listbox in one window. I'd like to open a 2nd window, have the users select from that window and repopulate the listbox in the parent window.

    I initially did this using frames instead of opening a new window and it worked for Netscape 3,4,6.2 and IE 4,5.5,6.

    Now I removed the frames and simply open a new window. It only works for Netscape (all versions) and doesn't work for any version of IE. I only changed Part 1 and didn't touch Part 2 when I switched from frames to opening a new window. Anyone have any ideas? In IE4, I'm getting a error msg that says "The server threw an exception". It looks like the error is on the new Option line.

    Here's what I do:
    //Part 1
    //************************************************
    // use opener with no frames
    // get the listbox on the parent window
    var e_main_seg = opener.document.emp_form.seg
    //************************************************
    //************************************************
    // use opener with frames
    // var e_main_seg = opener.parent.emp_main.document.emp_form.seg
    //************************************************

    //Part 2
    //delete the items in the listbox of the parent
    e_main_seg.length = 0;

    //now loop thru the items in the current listbox
    //if the item is selected, add it to the parent listbox

    var ctr = 0;
    for(var i=0; i<document.seg_form.seg_count.value; i++)
    {
    if (e.options[i].selected)
    {

    e_main_seg.options[ctr] = new Option(e.options[i].text, e.options[i].value);
    //also tried this syntax but it didn't work
    // e_main_seg.options[ctr] = new Option(e.options[i].text, e.options[i].value,false,false);
    ctr++;
    }
    }

  • #2
    one more thing

    One more thing I forgot to add. The deleting of items in the parent listbox does work. It's the adding of new items in the parent listbox that doesn't work.

    Comment


    • #3
      IE has the "security feature" that doesn't allow you to do this directly. What you need to do is to create the function that adds the option in your main window and call that function from the popup.

      part1:

      function addOption(optText,optValue) {
      document.emp_form.seg.options[document.emp_form.seg.options.length] = new Option(optText, optValue);
      }

      function clearOptions() {
      while (document.emp_form.seg.length > 1) {
      document.emp_form.seg.options[document.emp_form.seg.options.length-1]=null;
      }
      }

      part2:
      for(var i=0; i<document.seg_form.seg_count.value; i++) {
      if (e.options[i].selected) {
      opener.addOption(e.options[i].text, e.options[i].value);
      }
      }

      Comment


      • #4
        Thanks! That worked great!

        Comment

        Working...
        X