0

I got a question regarding my code. I got this function which opens a new window and creates a text input. Now I am trying to display the new entered text in the new window but unfortunately it does not work.. Thank you very much in advance

Text:

<input type="submit" value="Send" onclick="myAlert()">


<script>

    function myAlert()

    {

    var NewWindow= window.open();
    var nameValue = document.getElementById("vname").value;   
    NewWindow.document.write(nameValue);

    var input = document.createElement("input");
    input.type = "text";
    var btn = document.createElement("BUTTON");
    var t = document.createTextNode("Send");

    NewWindow.document.body.appendChild(input);
    btn.appendChild(t);  
    NewWindow.document.body.appendChild(btn);


    }


</script>
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Engineer
  • 43
  • 4
  • 5
    **java != javascript** – progyammer Nov 07 '16 at 17:55
  • java tag removed, javascript question tag added. Please understand that these are two completely different programming languages, about as closely related as ham is to hamburger, that if you mis-tag your question you will not get the right experts in to review it, and that this may hurt your chances of getting decent help. – Hovercraft Full Of Eels Nov 07 '16 at 17:56
  • Oke sorry won't happen again! – Engineer Nov 07 '16 at 17:57
  • Is this your fullcode? Try creating a fiddle with your code until now in jsfiddle or jsbin – Marco Nov 07 '16 at 18:07

2 Answers2

0

You don't have any input tag with id vanme . So the line,

var nameValue = document.getElementById("vname").value;

will definitely throw an error. Rightclick>Inspect Element > Console and see the error.

The code should work fine if you set an input tag with id vname .

Nandan Bhat
  • 1,573
  • 2
  • 9
  • 21
0

Try this:-

output = 'Hello, World!';
window.open().document.write(output);

link:-Add content to a new open window

Community
  • 1
  • 1
Razia sultana
  • 2,168
  • 3
  • 15
  • 20