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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Submit a form, show a popup 1

Status
Not open for further replies.

guitarzan

Programmer
Apr 22, 2003
2,236
US
I hope this post makes sense... I have a page, we'll call it send.asp, with the basic structure like below:

Code:
<FORM ... >

<TEXTAREA>
contains some html the user pastes in
</TEXTAREA>

<INPUT TYPE='SUBMIT' ...>
</FORM>

Clicking the submit button triggers my code to send an email using the html inside the TEXTAREA, and everything woroks fine. What I want to do, however, is have a Preview button (or hyperlink) that opens a new window and displays the html inside the TEXTAREA, in a new window.

Now, I can create a button or link with an ONCLICK event, something like ONCLICK="javascript:showpopup('preview.asp')", but this would not be able to pull the current contents of the TEXTAREA. I would have to submit the form to do that... but then I would have to re-display my input form (send.asp), and then, trigger a new window to popup... which I GUESS I could do with an ONLOAD statement, but this all seems wacky to me;

I'm thinking that there is probably a better way to do what I want, and my brain is just not seeing it today :) Does anyone have any suggestions?

Thanks!
 
You could do it with Javascript - here is one method:

Your form had a button which triggers a window opener

Code:
<script langauge="javascript" type="text/javascript">
function openPreview() {
	var myWin = window.open ("popup.html","myWindowName","menubar=0,resizable=0,width=500,height=350");
	myWin.focus();
}
</script>
	<form action="">
		<textarea id="myTextArea" name="myTextArea" cols="20" rows="5">
		</textarea>
		<input type="submit" id="btnSubmit" name="btnSubmit" value="Submit" />
		[COLOR=red]<input type="button" id="btnPreview" name="btnPreview" value="Preview" onclick="openPreview()" />[/color]
</form>

Your popup page contains the following:

Code:
<script language="javascript" type="text/javascript">
document.write(window.opener.document.getElementById("myTextArea").value);
</script>

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
window.opener... it's coming back to me now... I think that will work nicely! Will try on Tuesday and post my result. Thanks vicvirk!
 
vicvirk:
Belated thanks for this; it worked perfectly.
 
this is a nice method. i tried it with firefox and it worked, but not in ie.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top