Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form submission in a New Window !

Status
Not open for further replies.

fixthebug2003

Programmer
Joined
Oct 20, 2003
Messages
294
Location
US
Hi,
I need to submit a Form, say "myForm", which is in the main page. Once I submit the form the response from the Server should be opened in a New Window.
How can I accomplish this?

Fixthebug2003
 
you can use the TARGET attribute with a Form.
 
Try with target="_blank":
Code:
<form name="whatever" [b]target="_blank"[/b] action="blah.php">
<input type="text" name="test">
<input type="submit" value="submit form">
</form>
 
the page that is the target of the form should contain a JavaScript that opens the page you want in a new window like this:
Code:
window.open("url_of_page_to_open", "tmpWindow", "other_optional_params");
 
The "TARGET" attribute in the Form tag is what I need. The only thing is, if I set the TARGET to say "myNewWin", then a new window "myNewWin" is opened. We can cannot set the attributes of the window, like left,top, height, menubar etc..like we can do with a window.open right...

I guess onload of the new window, I 'll have to set these attributes..right?
 
In that case you can open dummy window from onsubmit event and "redirect" submit there:
Code:
<form name="whatever" action="blah.php" onsubmit="return checkForm();">
<input type="text" name="test">
<input type="submit" value="submit form">
</form>

<script language="javascript">
function checkForm()
{	var bRet;
	oFrm = document.forms["whatever"];
	if (oFrm.test.value== "")
	{	alert("Please enter some text");
		bRet = false;
	}
	else
	{	oWin = window.open("", "windowName", "height=200,width=400,toolbar=1" );
		oFrm.target="windowName";
		bRet = true;
	}
	
	return bRet;
}
</script>
Another alternative is to resize target window onload... kinda jumpy but works.
 
I have 3 different forms on the same page. Which ever is chosen would go to the same new window - which is exactly what I want.

In the answer you have here (which works GREAT!!!), you are hardcoding the form name into the script ["whatever"]
is there a way that it could be dynamic or pulled off of the form when submit button is clicked?

Jeni
 
This should work (form name is irrelevant for that purpose):
Code:
<form action="blah.php" onsubmit="return checkForm( [b]this[/b] );">
<input type="text" name="test">
<input type="submit" value="submit form">
</form>

<script language="javascript">
function checkForm( [b]oFrm[/b] )
...
 
I tried using this script on a php page - it doesn't seem to work, although I think I embedded it correctly - maybe not! Any tips?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top