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

How to open page 2 of form in same window or close pg 1 without alert?

Status
Not open for further replies.

Lisae123

Programmer
May 26, 2005
16
US
I have a multi-page form that is working, but I want it to open Page2.htm in the same window. Here's my code:

Page1.htm:

Code:
<html>
<head>
<title>New User Request</title>
<script language="JavaScript">
function opwin(url) {
nwwin = window.open(url);
}

var prevRole = "";

function showRole(currRole){

if (prevRole != ""){document.getElementById(prevRole).style.display='none'}
if (currRole != 0)
{document.getElementById(currRole).style.display='inline';
prevRole=currRole}
}

function disableRoles(isForm){

selectedRole = isForm.Department.selectedIndex;
if (selectedRole == 1)
{
document.getElementById('D101').disabled = true;
document.getElementById('D110').disabled = true;
return true;
}
if (selectedRole == 2)
{
document.getElementById('D100').disabled = true;
document.getElementById('D110').disabled = true;
return true;
}
if (selectedRole == 3)
{
document.getElementById('D100').disabled = true;
document.getElementById('D101').disabled = true;
return true;
}
else {
alert('Please choose a department');
return false;
}
}

</script>
</head>
<body>
<h1>Online Request</h1>
<form name="NewUser">
<p><b>Your First Name: <input type="text" name="ufname" size="30"></b></p>
<p><b>Your Last Name: <input type="text" name="ulname" size="30"></b></p>

<select name="Department" onchange="showRole(this.value)">
<option value="0" selected>Choose a Department</option>
<option value="D100">100 Corporate General</option>
<option value="D101">101 Corporate Restructuring</option>
<option value="D110">110 Merchandising General</option>
</select>

<select name="Role" id="D100" style='display:none'>
<option value="D1_0000001">D1 Role 000001</option>
<option value="D1_0000010">D1 Role 000010</option>
<option value="D1_0000020">D1 Role 000020</option>
</select>

<select name="Role" id="D101" style='display:none'>
<option value="D2_0000001">D2 Role 000001</option>
<option value="D2_0000010">D2 Role 000010</option>
<option value="D2_0000020">D2 Role 000020</option>
</select>

<select name="Role" id="D110" style='display:none'>
<option value="D3_0000001">D3 Role 000001</option>
<option value="D3_0000010">D3 Role 000010</option>
<option value="D3_0000020">D3 Role 000020</option>
</select>

<p><input type="button" value="Page2" onClick="opwin('Page2.htm');"></p>
</form>
</body>
</html>

...and Page2.htm:

Code:
<html><head>
<title>New User Request Page 2</title>
<script language="JavaScript">
function gtvals() {
d = document.NewUser2;
o = opener.document.NewUser;
d.ufname.value = o.ufname.value;
d.ulname.value = o.ulname.value;
d.Department.value = o.Department.value;
var whichRoleSelect = opener.document.getElementById(o.Department.options[o.Department.selectedIndex].value);
d.Role.value = (whichRoleSelect.options[whichRoleSelect.selectedIndex].value);
}
</script>
</head>

<body onLoad="gtvals();">

<form name="NewUser2" action="globalsendmail.asp" Method="Post">

<p><input type="text" name="ufname" onChange="nwclose();"></p>
<p><input type="text" name="ulname"></p>

<p><input type="text" name="Department"></p>
<p><input type="text" name="Role"></p>

<p><input type="submit" name="Submit" value="Submit"><input type="reset"
value="Reset"></p>
</form>
</body>
</html>

Anyone know how to load Page2.htm in the same window as Page1.htm was? I tried using "location.href = url;", but then it doesn't pass the data. Or, does anyone know how to get rid of that annoying alert that pops up when Page1.htm's window is closed in the current code?
 
run this function to close a window w/o getting the warning message:
Code:
function closeFunction() {
   top.opener = self;
   top.window.close();
}

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
Hmmm, I don't get the warning with that, but I also don't get the data from Page1.htm. And I do get an "Access is denied" error on line 6 (nwwin = window.open(url);).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top