PDA

View Full Version : object error



mravihpcl
11-11-2011, 02:37 PM
This is my script to pass values from parent to popup. I am getting an error [object HTMLInputElement]. Pls help me



<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>

jscheuer1
11-11-2011, 03:37 PM
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:


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();
}