Results 1 to 2 of 2

Thread: object error

  1. #1
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default object error

    This is my script to pass values from parent to popup. I am getting an error [object HTMLInputElement]. Pls help me


    Code:
    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <script type="text/javascript">
    function open_win()
    {
    var x=document.getElementById('1');
    var y=document.getElementById('2');
    var mywin=window.open("http://hpcl-4kgt5pwd85/hr/Lists/FormVclr/print.htm");
    mywin.document.write(x);
    mywin.document.write(y);
    
    }
    </script>
    </head>
    <body>
    <form id="100"method="post" action="">
    <input name="Text1" id="1" type="text">&nbsp;&nbsp;&nbsp;
    <input name="Text2" id="2" type="text"><br>
    
    &nbsp;<input type=button value="Open Window" onclick="open_win()" /></form>
    </body>
    Last edited by jscheuer1; 11-11-2011 at 03:25 PM. Reason: Format

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    function open_win()
    {
    var x=document.getElementById('1').value;
    var y=document.getElementById('2').value;
    var mywin=window.open("http://hpcl-4kgt5pwd85/hr/Lists/FormVclr/print.htm");
    mywin.document.write(x);
    mywin.document.write(y);
    mywin.document.close();
    }
    Note: The HTML spec requires that id's begin with a letter or an underscore, not a number. In most cases browsers will let you get away with using a a number though. The fact that you got:

    [object HTMLInputElement]
    means the element is being retrieved. But you don't want the entire element. I'm not 100% certain what you want from it, but it's very likely you want it's value as I have added to the code.

    Some browsers will require that you close the document after writing to it. This will not close the window. It simply allows the document to signal to the browser that it has finished loading.

    Using document.write() like that will likely overwrite the contents of print.htm. If your intention is to add to print.htm, rather than replace it with new content, a different approach may be required.

    And if you want to replace it, it need not be listed at all:

    Code:
    function open_win()
    {
    var x=document.getElementById('1').value;
    var y=document.getElementById('2').value;
    var mywin=window.open("");
    mywin.document.write(x);
    mywin.document.write(y);
    mywin.document.close();
    }
    Last edited by jscheuer1; 11-11-2011 at 03:44 PM. Reason: add notes
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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