View Full Version : Opening one of my saved forms and carrying data from one field across
Bobbo
02-02-2003, 07:39 PM
Hi, here is the case study.
I am in one of my web pages 'page1.htm' which has one field with the data value of 'value1'.
I am looking for a simple script that will allow me to;
open another of my web pages 'page2.htm', and display 'value1' in a specified field on 'page2.htm'!
Can anyone please help...I have looked evrywhere on the web!
Thanks
ConfusedOfLife
02-02-2003, 07:58 PM
Check this out my friend:
http://www.codingforums.com/showthread.php?s=&threadid=4555
And here it is a dummy file that I wrote with it:
The first file contains:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script>
function postVar(form)
{
target = form.action;
var str = "?";
for (i=0; i<form.elements.length; i++)
if ( form.elements[i].type != "submit" && form.elements[i].type != "button" )
str += form.elements[i].name + "=" + form.elements[i].value + "&";
str = str.substring( 0, str.length-1);
form.action += str;
}
</script>
</head>
<body>
<form name="sender" method="post" action="2.html" onsubmit="return postVar(this)">
Name : <input type="Text" name="name"><br>
Sirname : <input type="Text" name="sirname"><br>
<input type="Submit" value="Submit">
</form>
</body>
</html>
And the second file includes the followings:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script>
function getVar()
{
postedVals = location.search.substring(1);
$_GET = new Array();
if ( postedVals.length > 0)
{
qString = postedVals.split("&");
for ( i in qString)
$_GET[ qString[i].split("=")[0]] = qString[i].split("=")[1];
}
}
getVar();
</script>
</head>
<body bgcolor="#808000">
This is the second page!<br><br>
<form name="getter" method="">
Name : <input type="Text" name="name"><br>
Sirname : <input type="Text" name="sirname"><br>
<input type="Submit" value="Submit">
</form>
<script>
if ( postedVals.length > 0)
{
document.getter.name.value = $_GET["name"];
document.getter.sirname.value = $_GET["sirname"];
}
</script>
</body>
</html>
Bobbo
02-03-2003, 09:40 AM
Works a treat...thanks very much!
I'll be back......
Bobbo
02-03-2003, 11:10 AM
Looks like I might have been a bit hasty!
When on the web server I get the error message:
"Method Not Allowed
The requested method POST is not allowed for the URL /2.html."
Is this a show stopper??
manish71mishra
02-03-2003, 11:47 AM
Hi
If u use the page2.asp (instead of page2.html) then its very simple for u.
Just use the request.form.item('fieldname') to initialze the field in the page2.asp
IF ur interested in a asp soln i can post a sample code for u
let me know
Best wishes
Manish
Bobbo
02-03-2003, 12:41 PM
Would an .asp solution work on my UNIX server??
ConfusedOfLife
02-03-2003, 09:24 PM
Hey, javascript isn't server side. It means the pages that you see simply work in your own computer, on the server or anywhere else. I don't know what you're trying to do, but you can NOT send any variable by this script to a database or anything else. It's just written to send form variables from one page to another and it's just for demonstration purposes.
I don't know what you're doing, but you don't need .asp or any other server side language if you wana send your form elements from one page to another and this script is perfectly enough. If you can not modify it to answer your needs, I'll be glad to hear your case and help you.
Explain what you're doing and tell me if you were successful in working with this in your own machine. ( It's very simple, just save the first page as 1.html and the second as 2.html and put them in one directory and run 1.html and it's all done! )
Bobbo
02-04-2003, 10:34 AM
The two files that were posted in response to my problem DO work perfectly on the client, however, when the files were put on my web server, on hitting Submit and triggering the action the 'POST' action, created an error....see earlier!
I have created my own work around now, whereby the two files are installed, but I have avoided using the POST action and replaced it with the command
<a href="javascript:................
Thanks for your help, I am over the moon with the result!
Oh and my question about *.asp was in direct response to the posting prior to it from manish71mishra, which confused me as to its relevance to my problem.
ConfusedOfLife
02-07-2003, 02:09 PM
Ok. Maybe you're forgetting to put the http:// before your addresses or something like that. But if you had any other problems, it really helps if I can see your code. Have fun and bye.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.