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

Open popup by clicking the SUBMIT button 1

Status
Not open for further replies.

meldrape

Programmer
May 12, 2001
516
0
16
US
Hi there,

I have an opt-in email thing on a home page. When they enter their email address and click the "SIGN UP" button, I'd like it to open a popup window with their email in the form requesting additional info. I can do it through asp with a regular page opening no prob, but I want the window to be little and popup so I need to use javascript. Any help would be greatly appreciated. Thanks.
 
If all you need to know is how to run a function when the submit button is pressed, you just need to add this to the submit button:
onClick="preSubmit()"

If you want to know how to pass the e-mail address as a variable, you need to do this:

function preSubmit() {
var emailAddress = document.myForm.emailField.value;
var newWind = window.open("someURL.html","subWind")
newWind.document.formName.emailField.value = emailAddress;
}

If you don't want the form to be submitted until after the function has been run, use a normal button instead of a submit button and add this to the end of the function:

document.myForm.submit();
or
document.forms[0].submit();
 
I think this is what you want :
Code:
<!-- page one(main page) -->
<html>
<head>
<script language='javascript'><!--
function openpop()
{
var email = document.signup.email.value; //gets the email address from the form
var addform = window.open(&quot;addform.html&quot;,&quot;addform&quot;,&quot;height=400,width=300&quot;); //opens a new window
addform.form1.email.value = email; //sets the email textbox in the popup to the value in the form on the main page
}
//--></script>
</head>
<body>
<form name='signup'>
<input type=text name='email'>
<input type=button value=submit onClick='openpop()'>
</form>
</body>
</html>
<!-- end of the first page -->
and the second page looks something like this...its very bare but it should give you an idea
Code:
<!-- second page -->
<html>
<body>
Additional Info
<form name='form1'>
<input type=text name='email'>
<input type=button value=submit>
</form>
</body>
</html>
<!-- end of 2nd page -->

hope this helps
&quot;Those who dare to fail miserably can achieve greatly.&quot; - Robert F. Kennedy
So true..
 
Hmm... why not just put a target in the form tag?
Code:
<html>
<body>
<form method=&quot;POST&quot; action=&quot;myasppage.asp&quot; name=&quot;frmWhatever&quot; target=&quot;_blank&quot;>
<input type=&quot;text&quot; name=&quot;txtEmail&quot;>
<input type=&quot;submit&quot; value=&quot;Sign-Up!&quot;>
</form>
</body>
</html>

Just a thought,
-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
 
Hi Tarwn,

That would be ok but I don't want a full size window to open, just a popup. The post above yours is fine except I get the famous &quot;signup.email&quot; is null or not an object error. I have it within the form, etc. Don't know yet what's wrong...

Thanks!
 
when do you get it?

and do you call the function after the click of the button, because if it runs before the page completely loads you'll get that error.

if you could, posting your code would help. &quot;Those who dare to fail miserably can achieve greatly.&quot; - Robert F. Kennedy
So true..
 
Hi Dookie,

I took your exact code and created two pages from it (copied and pasted). When I click the submit button, the new window pops up but I get that error simultaneously.
 
All,

I just used the self.resizeTo(x,y) in the body onload of the target page. It works well enough. If anyone can think of something else more stable I can put in the target page, I'd appreciate it. Thanks.

 
Hi meldrape,
I have also tested the code by dookie2k2 but it seems to work fine. I have tested this on windows 2k, IE 5.5 sp2. Could you please tell us about machine configuration.

O/S :
Browser Name :
Version :

Please verify code once again, It should work fine [bigcheeks] Experience teaches slowly and at the cost of mistakes [pipe]
 
ahhh here we go, this should hopefully fix it, add the little highlited part to your page 2:
Code:
<!-- second page -->
<html>
<body
Code:
onload=&quot;document.form1.email.value = opener.document.signup.email.value&quot;
Code:
>
Additional Info
<form name='form1'>
<input type=text name='email'>
<input type=button value=submit>
</form>
</body>
</html>
<!-- end of 2nd page -->

that should fix it, hopefully &quot;Those who dare to fail miserably can achieve greatly.&quot; - Robert F. Kennedy
So true..
 
oh and take the line out that was causing the error in page 1..it was this one :
Code:
addform.form1.email.value = email;

smiletiniest.gif
&quot;Those who dare to fail miserably can achieve greatly.&quot; - Robert F. Kennedy
So true..
 
Hi Dookie,

No more errors, and it's working perfectly. Thanks so much for your perseverance!! :)
 
hey, no problem, thats why i'm here. :) &quot;Those who dare to fail miserably can achieve greatly.&quot; - Robert F. Kennedy
So true..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top