PDA

View Full Version : Pre-populating fields


stevenj_3
09-07-2001, 11:46 AM
Question?

Does anybody know of a script that will pre-populate forms on a sepearte page with the user's information. I know this can be done through use server side programming but I was looking to see if it could be done through a javascript?

Here's the process I'm looking to accomplish.
User types in information on page "A".
User clicks submit.
A new page is spawned with the text fields already pre-populated with the users information.

thanks in advance.

Dr. Web
09-07-2001, 12:52 PM
heres a very simple example if what your requesting.

this page can be save as anything you want:

<html>
<head>
<title>Untitled</title>
<script language="javascript">
function go_now(){
window.open ("child_data.htm", hotkeys="no", toolbars="no")
}
</script>
</head>
<body>
<form name="form1">
<input type ="text" value="stuff" name="textbox1" size="15">
<input type="button" value="click here!" onclick="go_now();">
</form>
</body>
</html>



this page should be saved as child_data.htm:


<html>
<head>
<title>Untitled</title>
<script language=javascript>
function set_form_data(){
var parent=window.opener.form1.textbox1.value;
window.document.form2.textbox2.value=parent;
}
</script>
</head>
<body onload="set_form_data();">
<form name="form2">
<input type="test" name="textbox2" size=15 disabled>
</form>
</body>
</html>

_mrkite
09-07-2001, 03:45 PM
Probably the best way to do this is to pass the form data to the second page via the url's query string, parse & decode it, and use scripting to display it in the second page's form fields. This is a bit like submitting a form to one's own site. Use this (http://www.faqts.com/knowledge_base/view.phtml/aid/969/fid/129/lang/) to get the data...

Dr. Web
09-07-2001, 04:39 PM
well I don't know if it is the BEST way. If you just want a receipt for the order, no need to put it into the URL. Plus the URL is restricted on the amount of information you can pass through it. Lets say you have a few textfields of information, such as delivery instructions, or comments. Would you want to pass these in the header? Probably not.

Plus with Javascript... there is no need to parse the info, just set up the new page, and send the form data to it.

_mrkite
09-08-2001, 06:43 PM
...some further reflections on the subject from another party [** (http://developer.netscape.com/viewsource/goodman_url_pass/goodman_url_pass.html)]. I wouldn't take it too seriously, though - he's not a 'Dr.' (and there aren't any cool graphics with his article)...