Click to See Complete Forum and Search --> : does Javascript do this?


sanjuT
04-21-2003, 11:10 AM
I am making an HTML form, and I need a pop up window with some items (textfields).

The user would click on a link in the parent window, a pop up would appear, the user would enter quantities in the available textfields, then click a 'Close window' or similar link.

The info would then automatically be filled in the parent window, in the appropiate area.

Can someone please let me know how this is done?

THANKS!!!

gil davis
04-21-2003, 12:05 PM
does javascript do this?It can.click on a link ... pop up would appear ... user would enter quantities ... click a 'Close window'In the "close window" link, you call a function that transfers the form data to the appropriate form field in the opener. For example:window.opener.document.formName.fieldName.value = document.popupFormName.fieldName.value;

sanjuT
04-21-2003, 01:49 PM
i am having problems with this...

i am using Netscape 4.76.

this is what i have on the child window 'Close Window' button:

<input type="submit" name="Submit" value="Close Window" onClick = window.opener.document.Layer11.items1.value = document.itemform.qty1.value;
window.close();>

what am i doing wrong?

Thanks!

gil davis
04-21-2003, 03:21 PM
Posting a link would help answer your question completely without playing message-pong.

I would have to see the HTML for both forms.

Using the submit button to close the window is rather dangerous from a timing point of view, unless you have cancelled the form's submit method in the form tag, since the form action may cause the location of the window to change.

sanjuT
04-21-2003, 04:07 PM
The forms are on an intranet, so I can't provide a link.

I have attached the important parts of the parent and child windows (forms).

I hope this helps you understand the problems I am having.

THANKS!

sanjuT
04-25-2003, 10:12 AM
i can close the pop up now, but not when i add the code to pass info to the parent window...this is probably cause that piece of code (passing info) is wrong...

can anyone help me?

I am using netscape 4.76, i need it to work on this browser.

here's the code that i have on a button in the child:

<input type="submit" name="Submit" value="Close Window" onClick = "parent.document.items1.value = document.itemform.qty1.value;
javascript:window.close()">


why won't the info from the child go to the parent?
i have layers, and for some other javascript calculations that i have on another page, i have to reference the layer, like this:

tot += (1.13 * document.Layer11.document.order.qty4.value);
tot += (2.23 * document.Layer11.document.order.qty5.value);

I've tried to do it this way too, but to no avail..

i debug, and get the message that document.parent has no properties.

If anyone can help, i'd really appreciate it! this has been bugging me for a few days now.

THANKS!!

Jona
04-25-2003, 11:25 AM
It's not "document.parent," it's window.parent.

sanjuT
04-25-2003, 01:23 PM
i still get the 'no properties' error..

Jona
04-25-2003, 01:26 PM
<input type="submit" name="Submit" value="Close Window" onClick = "parent.document.items1.value = document.itemform.qty1.value;
javascript:window.close()">


Should be:

<input type="submit" name="Submit" value="Close Window" onClick = "parent.document.items1.value = document.itemform.qty1.value; window.close()">

sanjuT
04-25-2003, 01:39 PM
as usual, i get the no properties error...

i am sure someone has done this before in NS4.7..i think...

gil davis
04-25-2003, 04:02 PM
FIRST (Parent) FORM:

<input type="submit" name="Submit5" value="Items" onClick = NewWin=window.open('food1.html')>
<input type="text" name="items1" size="18">


CHILD FORM:

<input type=text name=qty1 size=3">
</font></b></font></div>
</td>
<td colspan="6">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><b>Breakfast
Pastries</b><br>
$0.88 each<br>

<input type="submit" name="Submit" value="Close Window" onClick = window.opener.document.Layer11.items1.value = document.itemform.qty1.value;
window.close();>
If this is truly directly from your online file, then your errors are apparently the lack of quotes around the onclick event handlers.
FIRST (Parent) FORM:
<input type="submit" name="Submit5" value="Items" onClick="NewWin=window.open('food1.html')">
<input type="text" name="items1" size="18">

CHILD FORM:
<input type="text" name="qty1" size=3"></font></b></font></div></td>
<td colspan="6">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><b>Breakfast Pastries</b><br>$0.88 each<br>

<input type="submit" name="Submit" value="Close Window" onClick="window.opener.document.Layer11.items1.value=this.form.qty1.value;window.close()">
Netscape is stricter on syntax and tag nesting than IE.

I am concerned that you are attempting to hide a portion of one of the forms using a layer. This will not work in NS 4, because making a layer scriptable creates a document within a document and breaks the form. This would render the form elements unreachable by Javascript. Since you have not posted the rest of the HTML for the form, I cannot confirm that you have nested the form elements correctly.

sanjuT
04-28-2003, 09:03 AM
thanks, but still the errors.

Is there a way I could send you the 2 pages (parent and child) to take a better look at?

I'll understand if you do not want to trouble yourself with my problems, it's just that i really need to make this work with NS4.7, and I have hit a wall.

Thanks!

gil davis
04-28-2003, 09:18 AM
Zip all the relevant files and attach it to you next post (look for the Browse button below the reply window).

sanjuT
04-28-2003, 09:34 AM
thanks a lot, here they are!

sanjuT
04-28-2003, 09:36 AM
here's the child page.

gil davis
04-28-2003, 09:46 AM
See attached.<input type="submit" name="Submit" value="Close Window" onClick ="window.opener.document.Layer11.document.items1.value=this.form.qty1.value;window.close()">needed to be<input type="submit" name="Submit" value="Close Window" onClick ="window.opener.document.Layer11.document.form1.items1.value=this.form.qty1.value;window.close()">

sanjuT
04-28-2003, 10:10 AM
AWESOME!!
thanks a lot, it works!

now I realize that i have up to 10 items that i need to send to the parent form (all the items go into the same textfield in the parent).

I think I need to use a function that checks if the child's textfields are null or not, and if not, to enter the value into the parent.

I think I can also add static text to the parent textfield (ie. Breakfast Pastries, as in 3 Breakfast Pastries) using the function that checks for the nulls.

Am I on the right track? I assume I use what you supplied to reference the parent form from the function in the child.

THANKS!!!!

sanjuT
04-28-2003, 02:53 PM
this is the function i've come up with:

<script>
var mess;
var newitem;
mess="Your current order for the first break is:\n";
function send() {
if (document.itemform.qty1.value!="") {
newitem = "\n" + document.itemform.qty1.value + " Continental Breakfast(s)";
}

if (document.itemform.qty2.value!="") {
newitem += "\n" + document.itemform.qty2.value + " The Healthy Start(s)";
}

if (document.itemform.qty3.value!="") {
newitem += "\n" + document.itemform.qty3.value + " At the Wire Breakfast Buffet(s)";
}
confirm(mess + newitem);
if (newitem!="") {
window.opener.document.Layer11.document.form1.items1.value=newitem;
}

window.close();

}
</script>

There's a problem:
when i hit 'Cancel' on the confirm dialog box, the form reacts the same as if i hit 'OK'. i do not return to the popup. instead the values are sent to the parent form.

If anyone can help, thanks!!!

sanjuT
04-28-2003, 03:52 PM
i figured it out:
if (confirm(mess + newitem) && (newitem!="")) {
window.opener.document.Layer11.document.form1.items1.value=newitem;
window.close();
}

sanjuT
04-29-2003, 09:42 AM
a little problem...AGAIN!

with this code, I get a confirm dialog box to pop up before the info goes to the parent.
the thing is, when i DO NOT select the first item (Continental Breakfast) I get the word 'undefined' as the first item (in both the confirm box and when the parent recieves the info).

<script>
var mess;
var newitem;
mess="Your current order for the first break is:\n";
function send() {
if (document.breakitems.qty1.value!="") {
newitem = "\n" + document.breakitems.qty1.value + " Continental Breakfast(s)";
}

if (document.breakitems.qty2.value!="") {
newitem += "\n" + document.breakitems.qty2.value + " The Healthy Start(s)";
}

if (document.breakitems.qty3.value!="") {
newitem += "\n" + document.breakitems.qty3.value + " At the Wire Breakfast Buffet(s)";
}
if (document.breakitems.qty4.value!="") {
newitem += "\n" + document.breakitems.qty4.value + " Breakfast Pastries";

if (confirm(mess + newitem) && (newitem!="")) {
window.opener.document.Layer11.document.form1.items1.value=newitem;
window.close();
}

}
</script>

I am pretty sure it has to do with this part from the code for the first item:
newitem = "\n" + ect.....

If I use:
newitem += "\n" + ......
for the first item code, I still get the 'undefined'.

Does anyone know how I can fix this?

THANKS!!!!