Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2006
    Location
    Illinois
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer JavaScript cloneNode() with Select Boxes

    We have a "printer-friendly" function on our Intranet site which creates a pop-up window containing the page contents minus the header and left navigation. The JavaScript function takes the contents of the page (as defined by a div ID) and then strips out colors, borders, etc. To access the page contents in the new window, we do the following:

    var outputObj = document.getElementById("contentArea");
    var ccOutputObj = outputObj.cloneNode(true);

    The problem is, cloneNode() does not preserve select box selections. If you select, let's say, 4 in a quantity select box, it defaults to 1 when the page is printed. The other form elements (input fields, radio buttons) preserve the values correctly.

    Does anyone know how to preserve select box values when cloneNode() is used?

    Thanks!
    Sarah

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,504
    Thanks
    3
    Thanked 501 Times in 488 Posts
    save the selected Index then select the clone to that index
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    New Coder
    Join Date
    Aug 2006
    Location
    Illinois
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you give an example of how to do this? This has to be dynamic and reusable across pages.

    Thanks.

  • #4
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Why not lose the javascript solution all together and use an at print style sheet?

    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #5
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Basscyst, does have a point.

    Quote Originally Posted by probey20
    Can you give an example of how to do this?
    Use document.getElementById("contentArea").getElementsByTagName('select') and a for() loop to find all of the value selectedIndex property of each select element in the parent page and then set it in the child page.
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
    Java != JavaScript && JScript != JavaScript
    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

  • #6
    New Coder
    Join Date
    Aug 2006
    Location
    Illinois
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Basscyst, I wish I could do away with the JavaScript function altogether... but our user base is accustomed to the way we do printer friendly now and they don't want me changing it up

    With that said, I'm going to give Kravvitz's suggestion a try tomorrow. Thanks everyone for your help!
    Sarah


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •