Nose Programmer
Nose Programmer

Reputation: 115

write from an html to another using JavaScript

I have a form written in html that contains a form. I must write another html page using javascript and it will contain the information that the user writes in the form.

<!DOCTYPE html>
<html>
<head>
<script>
function validateForm()
{
var x=document.forms["myForm"]["fname"].value;
if (x==null || x=="")
  {
  alert("First name must be filled out");
  return false;
  }
}
</script>
</head>

<body>
<form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post">
First name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>
</body>

I have already used appendchild but it doesn't accept the name of the button.

Upvotes: 0

Views: 63

Answers (2)

Deepak Sharma
Deepak Sharma

Reputation: 4170

If you mean get the value from FORM and show it in popup why don't u try this..

check the fiddle

<html>
<script>
function f()
{
   var name = document.getElementById("name").value;
   var myWindow = window.open("","MsgWindow","width=400,height=100");
   myWindow.document.write("User Name = <b><i>"+name+"</i></b>.");
   return false;
}
</script>
<body>
  <form onsubmit="return f()" >
    <input type="text" id="name" />
    <input type="submit" />
  </form>
</body>
</html>

Upvotes: 1

Afzaal Ahmad Zeeshan
Afzaal Ahmad Zeeshan

Reputation: 15860

If that's on the page itself then you can create a new html document using

document.createElement()

but if you want to do that in any other window, then that won't be possible. Since JavaScript can't handle the events on other windows.

For the method: https://developer.mozilla.org/en-US/docs/Web/API/document.createElement

Then you can append the text to it, using the values from the form.

Upvotes: 2

Related Questions