By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

Mulitple Input Values passed from Popup Window

P: n/a
OK, I need to do three different things.

On the ONLOAD event I would like a popup box to open. In this popup
box I need two text boxes. One for the UserName and one for the
BillingTo name. After entering these two items the user can either hit
the enter key or press the submit button. The popup window will close
and then those two text boxes in the original webpage will be filled in
automatically.

I would like to have the two fields to be validated so the popup won't
close until both text boxes are filled in.

So far I have used the function from javascript.internet.com in the
header of the original page. I have tried to make so that when the
first popup closes the second popup will open. I can get the variables
to pass the main page but I feel it would be more effecient to have
both text boxes in the same popup instead of having two.

<html>
<head>
<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function explain(name, output) {
newwin = window.open('','','top=150,left=150,width=325,heig ht=300');
if (!newwin.opener) newwin.opener = self;
with (newwin.document)
{
open();
write('<html>');
write('<body onLoad="document.form.box.focus()"><form name=form
onSubmit=window.close()> <br>');
write('<p>' + name + ' ');
write('<p><center> Sender: <input type=text name=box size=20
onKeyUp=' + output + '=this.value>');
write('<p><input type=button value="Click to close when finished"
onClick=window.close()>');
write('</center></form></body></html>');
close();
}
}

// End -->

<!-- Begin
function billingto(name, output) {
newwin = window.open('','','top=150,left=150,width=325,heig ht=300');
if (!newwin.opener) newwin.opener = self;
with (newwin.document)
{
open();
write('<html>');
write('<body onLoad="document.form.box.focus()"><form name=form
onSubmit=window.close()> <br>');
write('<p>' + name + ' ');
write('<p><center> Sender: <input type=text name=box size=20
onKeyUp=' + output + '=this.value>');
write('<p><input type=button value="Click to close when finished"
onClick=window.close()>');
write('</center></form></body></html>');
close();
}
}
// End -->

</script>
</head>

<body ONLOAD="explain('Please enter the name of the person sending this
shipment here and it will be copied into the form for you.',
'opener.document.form.username.value');">
<center>
<form name=form method=post>

User Name: <input type=text name="username" size=10
onfocus="billingto('Please enter the billing to person',
'opener.document.form.billing.value');">

<br>
Password: <input type=text name="billing" size=10>

</form>
</center>

</BODY>
</html>

Thanks for any help - Billy

Mar 24 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I have figured out how to have both text boxes into one popup and how
to get those values passed to the main page. Here is the code in my
head tag:

<!-- Begin
function shippingform(name, billing, output, output2) {
newwin = window.open('','','top=150,left=150,width=500,heig ht=200');
if (!newwin.opener) newwin.opener = self;
with (newwin.document)
{
open();
write('<html>');
write('<body onLoad="document.form.box.focus()">');
write('<form name=form onSubmit=window.close()>');
write('<center>');
write('<br>');
write(name);
write('<br>');
write('Sender: ');
write('<input type=text name=box size=20 onKeyUp=' + output +
'=this.value>');
write('<br>');
write('<br>');
write(billing);
write('<br>');
write('BillingTo: ');
write('<input type=text name=billingtobox size=20 onKeyUp=' + output2 +
'=this.value>');
write('<br>');
write('<input type=button value="Click to close when finished"
onClick=window.close()>');
write('</center>');
write('</form>');
write('</body>');
write('</html>');
close();
}
}

// End -->

</script>
=======================
=======================

Here is my body tag:
<body ONLOAD="shippingform('Please enter the name of the person sending
this shipment here.', 'Enter Advanced.1, Client, or Personal for
verification on who will get billed',
'opener.document.form.username.value',
'opener.document.form.billingtobox.value');">
<form method="POST" name="form">

=======================
=======================

Here are the text boxes on the main page:

<input type="text" name="username" size=53>
<input type=text name="billingtobox" size=81>

=======================
=======================

The only thing I really need now is for some kind of verification to
happen. I don't want the popup to close until both fields are filled
in.

Also, somehow the onsubmit stopped working. So the only way to close
the popup is to click the button or click the red X. Any suggestions?

Thanks.

Mar 24 '06 #2

P: n/a
ja*********@gmail.com wrote:
I have figured out how to have both text boxes into one popup and how
to get those values passed to the main page. Here is the code in my
head tag:
You mean the `head' _element_, which consists of an optional
start tag, content, and an optional end tag, in HTML 4.01.
<!-- Begin
Obsolete, potentially harmful nonsense. Remove it.
function shippingform(name, billing, output, output2) {
newwin = window.open('','','top=150,left=150,width=500,heig ht=200');
I hope `newwin' is declared somewhere with `var'.
if (!newwin.opener) newwin.opener = self;
Nonsense, remove it.
with (newwin.document)
{
The `with' statement is deprecated because of its side effects, and it is
unnecessary here.
open();
write('<html>');
The markup that you are generating (and that contains the generating code)
is not Valid HTML.

<URL:http://validator.w3.org/>
write('<body onLoad="document.form.box.focus()">');
Consecutive calls of document.write() are inefficient and error-prone,
especially when only a tag and not the whole element is written. Should
be more like

newwin.document.write(
'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"'
+ ' "http://www.w3.org/TR/html4/loose.dtd">'
+ '<html>'
+ ...);

The most efficient way is joining an Array:

newwin.document.write([
'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"',
' "http://www.w3.org/TR/html4/loose.dtd">',
'<html>',
...
].join('\n'));

The latter is supposed to work since JavaScript 1.3 (NN 4.06, 1998 CE),
JScript 2.0 (IE 2.0, 1996/1997 CE), and in ECMAScript Edition 3 (December
1999 CE) implementations.
[...]
// End -->
Unnecessary. Remove it.
[...]
<body ONLOAD="shippingform('Please enter the name of the person sending
this shipment here.', 'Enter Advanced.1, Client, or Personal for
verification on who will get billed',
'opener.document.form.username.value',
'opener.document.form.billingtobox.value');">
Element types _and_ attribute names should be lowercase, even though
HTML is case-insensitive regarding this.

When event handler code turns into spaghetti code like this, it should
be moved into a function, and that function should be called instead.
<form method="POST" name="form">
The `action' attribute is missing, and the form most certainly does not
need a name. There is the document.forms collection; if the form is
the first or only one within the document, it can be referred backwards
compatible and standards compliant with `document.forms[0]'. The name
`form' is unwise anyway, especially when used in proprietary syntax
`document.form' because `document.forms' exists.
[...]
Here are the text boxes on the main page:

<input type="text" name="username" size=53>
type="text" is redundant here, and all attribute values should be quoted.
<input type=text name="billingtobox" size=81>
[...]
The only thing I really need now is for some kind of verification to
happen. I don't want the popup to close until both fields are filled
in.
Your current code will close the window before anything of the input can
be processed or submitted, due to `onsubmit=window.close()' [where the
attribute value MUST be enclosed in single or double quotes because of
the `(' or `)'].

Return `false' to the `onsubmit' handler if you want the form not to be
submitted, and do not call window.close() unconditionally if you do not
want the window to be closed always.
Also, somehow the onsubmit stopped working.
It never worked this way. `onsubmit' code is executed when the `submit'
event of the form occurs, i.e. if the submit button is activated or
(usually) the Return key is pressed when an input control has focus,
_before_ the form is actually submitted.
So the only way to close the popup is to click the button or click the
red X.
There is no red X here. You must be talking about one of the dozens of
window managers or user agents out there.
Any suggestions?


Read the FAQ, search the archives, so get a minimum clue,
and then get back here. <URL:http://jibbering.com/faq/>
PointedEars
Mar 24 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.