faqts : Computers : Programming : Languages : JavaScript : Forms

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

123 of 168 people (73%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How do I create a custom popup form which submits back to the parent window and works in IE or NS?
How can I replace prompt with a self made dialog which works on both IE and Netscape?

May 3rd, 2000 14:49
Chris Durkin, irt.org


Before opening the popup window, you need to set a value for the name 
property of the main window, which is blank by default. The child 
window's form can then refer back to the parent using the TARGET 
attribute. To close the child form after submitting it, use an arbitrary 
interval with setTimeout()
EXAMPLE - save the following as "main.htm":
<html>
<head>
<title>Login Demo</title>
<script language="javascript">
	window.name="main";
	function login () {
		w = window.open("login.htm", "login", 
"width=250,height=100,resizable=no,scrollbars=no,dependent=yes,toolbars=
no,status=no");
	}
</script>
</head>
<body>
<script language="javascript">
	var qt = String.fromCharCode(34);
	var username = "Default";
	pos = window.location.search.indexOf("=");
	if (pos > -1) {username = window.location.search.substr(pos + 
1);}
	document.write("Welcome to the demo. You are currently logged in 
as <b>" + username + "</b>. ");
	document.write("To change user, <a href=" + qt + 
"javascript:login();" + qt + ">Click Here</a>.");
</script>
</body>
</html>
...and the following as "login.htm":
<html>
<head><title>Login</title></head>
<body>
<form action="main.htm" target="main" 
onsubmit="setTimeout('self.close()',250);">
Username: <input type="text" name="username" size="15" 
maxlength="10"><br>
<input type="submit" value="Submit"> <input type="button" value="Cancel" 
onclick="self.close();">
</form>
</body>
</html>
...and put them in the same directory. load "main.htm" to test