Click to See Complete Forum and Search --> : Pop-up's and script


David Harrison
01-05-2003, 10:52 AM
First of all can you please download and unzip the attachment so you might understand what I'm asking.

Open the HTML document entitled "Add Up". You will see two text boxes, put a number in each one and press "Add Up", A pop-up window will open with the answer in.

That's fine, it works great however, it's not what I need.

Now open the HTML document entitled "Click To Add Up" you will see only one button, press it and a pop-up window will appear with "this is a pop-up window" written in it. How would I get the add up script to work in that pop-up window?

khalidali63
01-05-2003, 11:30 AM
Let me understand it correctly.
you want the addition fields to be on the pop up window?.If yes
then create this page with say "addup.html" name and where you open the window with the code like

window.open("addup.html"

it will open this page ???

is it something that u want ot do

David Harrison
01-05-2003, 11:46 AM
What I want is for the page "Click To Add Up.html" when you click the button to create a pop-up window with the add upi script on it and when you press submit on that page i want it to careate a pop-up window again with the answer on it.
Basically all of the information for this must be contained on one page.

David Harrison
01-05-2003, 03:33 PM
Just to simplify it a bit more, the question is...
How can I use javascript in a pop-up window?

DarkSoul
01-06-2003, 04:36 AM
Don't know why you used the 'writeln'?


This is your main.html (or whatever)

<html>
<head>
<script language="javascript">
<!--
function Popup(){

var Popup = window.open("","PopUp","height=300, width=400, scrollbars=yes, resizable=yes, status=yes");
Popup.document.write("<html><head><title>Pop-Up</title></head><body onload=\"create(this.form)\">");
Popup.document.write("<p align=\"center\"><font face=\"verdana\" size=\"4\"><b>Pop-Up</b></font></p>");

Popup.document.write("<p align=\"center\"><font face=\"verdana\">This is a pop-up window.</font></p>");
Popup.document.write("<script language='JavaScript' src='addup.js'>Addup();</script>");
Popup.document.write("<p align=\"center\"><font face=\"verdana\"><a href=\"javascript:window.close();\">Close</a></font></p></body></html>");
Popup.document.write("<form name='addup'><input type='text' name='a' size='20'><input type='text' name='b' size='20'><input type='submit' value='Add Up' onclick='Addup()'></form>");
}
//-->
</script>
</head>
<body onload="Popup()">
</body></html>

Here you have your Addup() function in the addup.js
<!--
function Addup(){

a=addup.a.value;
b=addup.b.value;

Addup = window.open("","AddUp","height=300, width=400, scrollbars=yes, resizable=yes, status=yes");
Addup.document.writeln("<html><head><title>Add Up</title></head><body onload=\"create(this.form)\">");
Addup.document.writeln("<p align=\"center\"><font face=\"verdana\" size=\"4\"><b>Add Up</b></font></p>");

Addup.document.writeln((1*a)+(1*b))

Addup.document.writeln("<p align=\"center\"><font face=\"verdana\"><a href=\"javascript:window.close();\">Close</a></font></p></body></html>");}


//-->

It seemed to me the only way to do it, is to call the function from an external file, loaded with the <script> tag within the body. Allowing to define in which body you're adding code, in a way. (some scripts just don't work without that :cool: )