PDA

View Full Version : I'm still having problems


stevenj_3
09-17-2001, 01:44 PM
Last week I submitted a question on parsing information through the use of method="get".

I need to collect users information on page 1 through a form. When they press submit I will get a long url with the users information. Now, I need to populate a form on the second page with the users information. My first page looks something like this.

<html>
<head>
</head>

<body topmargin="0" marginheight="0" marginwidth="0" leftmargin="0">
<table width="760" cellpadding="0" cellspacing="0" border="0">
<form action="putinfohere.html" method="get">
<TR>
<td valign="top" align="left"><input type="text" name="input01"><input type="submit" value="submit"></td>
</tr>
</form>
</table>

The Second page will take that submitted information and display it in seperate fields.

Am I crazy or can this be done?

scoutt
09-17-2001, 05:28 PM
<form action="putinfohere.html" method="get">
<TR>
<td valign="top" align="left"><input type="text" name="input01"><input type="submit" value="submit"></td>
</tr>
</form>

well the second page will be look like this.
<input type="text" value="$input01" name="whatever">

or you have to use a serverside script like cgi or php

_mrkite
09-17-2001, 11:21 PM
You didn't specify if the data was being posted to a server-side script or just passed to the second page.
Assuming it's the latter, write a script - to run onload in the second page, that parses the query string
(location.search) and extracts the data, moving it into the appropriate form fields. Like this:

[page1.html]


<html>
<head>
<title>untitled</title>
</head>
<body topmargin="50" marginheight="50" marginwidth="50"
leftmargin="50" bgcolor="#aaaaaa" onload="document.forms[0].reset()">
<h2>First Page</h2>
<form action="page2.html" method="get">
<table cellpadding="0" cellspacing="4" border="3">
<tr><td><input type="text" name="input01"></td></tr>
<tr><td><input type="text" name="input02"></td></tr>
<tr><td><input type="text" name="input03"></td></tr>
<tr><td><input type="text" name="input04"></td></tr>
<tr><td align="center"><input type="submit" value="submit"></td></tr>
</table>
</form>
</body>
</html>

[page2.html]


<html>
<head>
<title>untitled</title>

<script language="JavaScript" type="text/javascript">

function parseQueryString (str) {
str = str ? str : location.search;
var query = str.charAt(0) == '?' ? str.substring(1) : str;
var args = new Object();
if (query) {
var fields = query.split('&');
for (var f = 0; f < fields.length; f++) {
var field = fields[f].split('=');
args[unescape(field[0].replace(/\+/g, ' '))] =
unescape(field[1].replace(/\+/g, ' '));
}
}
return args;
}

function displayIt() {
var args = parseQueryString();
for (var arg in args) {
document.forms[0][arg].value = args[arg];
}
}

window.onload = displayIt;

</script>
</head>
<body topmargin="50" marginheight="50" marginwidth="50"
leftmargin="50" text="#ffffff" bgcolor="#000000">
<h2>Second Page</h2>
<form action="page2.html" method="get">
<table cellpadding="0" cellspacing="4" border="3">
<tr><td><input type="text" name="input01"></td></tr>
<tr><td><input type="text" name="input02"></td></tr>
<tr><td><input type="text" name="input03"></td></tr>
<tr><td><input type="text" name="input04"></td></tr>
<tr><td align="center"><input type="button" value="back"
onclick="this.form.reset();history.go(-1)"></td></tr>
</table>
</form>
</body>
</html>

The excellent parsing function is courtesy of M. Honnen (http://www.faqts.com/knowledge_base/view.phtml/aid/969/fid/124).