logo Send us mail:
contact@reliancewisdom.com
WhatsApp or call:
+234 (0)808 881 1560
TOGGLE NAVIGATION
Back to All Forum Posts
Form Submission to a New Window with JavaScript
Ishola Wasiu    Jan 1, 2017 at 04:40 PM    1    560

Please I need help. I am new to programming. I have an HTML form. How can I submit it to a new window with JavaScript by writing the form data to the window and setting the window's properties such as with and height? This is my code for the form:

<form method="post" enctype="multipart/form-data" name="myform" target="_top">
<fieldset>
<span class="style2">
<label for="name"><strong>Name: </strong></label>
</span>
<input type="text" name="name" id="name" value="" />
<label for="age"><br />
<br />
<span class="style1">Age: </span></label>
<input type="text" name="age" id="age" value="" />
<br />
<br />
<a href="javascript:void(0)" onclick="open_win()" >Dynamic submission </a>
<br />
</fieldset></form>

Back to All Forum Posts

1 Answer
Ishola Ayinla says...
Jan 1, 2017 at 05:30 PM

The solution is very simple. First, create a file and name it "submit_form.htm" and put this in it's head section:

<script type="text/javascript">
<!--
function open_win()
{
var a=document.myform.name.value;
var b=document.myform.age.value;
var c=window.open("result.htm","post_it",
"width=300,height=600");
c.document.write("<font size='8'><b>Welcome to my site "+a+"! You are "+b+" years old.</b></font><p><input type='button' value='Close Window' onclick='window.close()'></p>");
}
//-->
</script>

and this in it's body section:

<form method="post" enctype="multipart/form-data" name="myform" target="_top">
<fieldset>
<span class="style2">
<label for="name"><strong>Name: </strong></label>
</span>
<input type="text" name="name" id="name" value="" />
<label for="age"><br />
<br />
<span class="style1">Age: </span></label>
<input type="text" name="age" id="age" value="" />
<br />
<br />
<a href="javascript:void(0)" onclick="open_win()" >Dynamic submission </a>
<br />
</fieldset></form>

and create another empty file called "result.htm" in the same directory.


Full Details