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

Passing data on multi-page form in same window

Status
Not open for further replies.

Lisae123

Programmer
May 26, 2005
16
0
0
US
I have a three page form, and I want each page to open in the same window, but when I use "location.href" it won't pass the data entered in page 1 to page 2, or page 1 & 2 to page 3. Anyone know how to make BOTH of these things (passing data AND opening in the same window) work at the same time? Here's my sample code (just 2 pages):

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>

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="hidden" id=hidden1 name="Subject Line" value="New Test!">
	<INPUT TYPE="hidden" id=hidden2 name="To" value="email@address.com">
	<INPUT TYPE="hidden" id=hidden3 name="CC" value="">
	<INPUT TYPE="hidden" id=hidden4 name="Bcc" value="">
	<INPUT TYPE="hidden" id=hidden5 name="Link_URL" value="Page1.htm">
</p>

<p><input type="text" name="ufname"></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>

When I change:
Code:
function opwin(url) {
nwwin = window.open(url);
}

to:

Code:
function opwin(url) {
location.href(url);
}

it will open page2.htm in the same window as page1.htm was, but it doesn't pass the data, and it gives an "'opener document' is null or not an object" error. Please help!
 
the "opener" property will exist only when the window was opened by another using window.open()

it looks like you're using ASP - wouldn't this task be better suited to writing the form field values server-side from the request.form object?


-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Ya, I really do need to learn ASP (and someday I sure hope to have the time!), but the script you see called in the code was written by someone no longer here. Does that mean it can't be done with JavaScript?
 
you'll have to change in Page1:
from
Code:
<form name="NewUser">

and 

<input type="button" value="Page2" onClick="opwin('Page2.htm')">
to
Code:
<form name="NewUser" action="Page2.htm" method="GET">

and

<input type="submit" value="Page2"  />

and in Page2.htm, using code from faq216-3858, something like:
Code:
<script language="JavaScript">

function gtvals() {
	//  make vars from querystring params
	var p = location.search.substring(1).replace(/\+/g,' ').split("&");
	for(var i = 0; i < p.length; i++){
		v = p[i].split("=");
		window[unescape(v[0])] = unescape(v[1])
	}

	d = document.NewUser2;
	d.ufname.value = window["ufname"];
	d.ulname.value = window["ulname"];
	d.Department.value = window["Department"];
	d.Role.value = window["Role"];
}

</script>

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top