Create a new window and add form controls in JavaScript

Description

The following code shows how to create a new window and add form controls.

Example


<html>
<script language="JavaScript">
function openWin(){<!--from w ww .  j  a  va  2 s  .co  m-->
var myBars = 'directories=no,location=no,menubar=no,status=no';

myBars += ',titlebar=no,toolbar=no';
var myOptions = 'scrollbars=no,width=400,height=200,resizeable=no';
var myFeatures = myBars + ',' + myOptions;
var myReadme = 'This is a test.'

var newWin = open('', 'myDoc', myFeatures);

newWin.document.writeln('<form>');
newWin.document.writeln('<table>');
newWin.document.writeln('<tr valign=TOP><td>');
newWin.document.writeln('<textarea cols=45 rows=7 wrap=SOFT>');
newWin.document.writeln(myReadme + '</textarea>');
newWin.document.writeln('</td></tr>');
newWin.document.writeln('<tr><td>');
newWin.document.writeln('<input type=BUTTON value="Close"');
newWin.document.writeln(' onClick="window.close()">');
newWin.document.writeln('</td></tr>');
newWin.document.writeln('</table></form>');
newWin.document.close();
newWin.focus();
}
</script>
<body>

<form>
<b>Click the following button to open a new window: </b>
<input type=BUTTON value="Open" onClick='openWin()'>
</form>
</body>
</html>

Click to view the demo

The code above generates the following result.

Create a new window and add form controls in JavaScript