...

View Full Version : Pass values using Javascript



dlg0351
03-17-2005, 02:48 AM
I have a form and want to use Javascript to pass the values from one page to the other. I am able to get the first pass to work but I am not sure what should go in the value of the hidden fields.

Any help is greatly appreciated.

Page 1:


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

<body>

<form name="myform" method="get" action="test2.html">
Email: <input type="text" name="Email">
<input type="hidden" name="ID" value="12345">
<input type="submit" value="Submit">
</form>

</body>
</html>


Page 2:


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

<script LANGUAGE="JavaScript">
function decodeSearchString() {
var nameValue = new Array();
var searchStr = unescape(location.search.substring(1));
if (searchStr) {
var formElement = searchStr.split("&");
var tmpArray = new Array();
for (k = 0; k < formElement.length; k++) {
tmpArray = formElement[k].split("=");
nameValue[tmpArray[0]] = tmpArray[1];
}
}
return nameValue
}

var srchData = decodeSearchString();
</SCRIPT>
</head>

<body>

<form name="myform" method="get" action="test3.html">
<SCRIPT LANGUAGE="JavaScript1.2">
<!--
document.write("Email: " + srchData.Email);
document.write("<br>");
document.write("ID: " + srchData.ID);
document.write("<br>");
//-->
</script>

Name: <input type="text" name="Name">


<input type="hidden" name="Email" value="???">
<input type="hidden" name="ID" value="???">
<input type="submit" value="Submit">
</form>

</body>
</html>


Page 3:


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

<script LANGUAGE="JavaScript">
function decodeSearchString() {
var nameValue = new Array();
var searchStr = unescape(location.search.substring(1));
if (searchStr) {
var formElement = searchStr.split("&");
var tmpArray = new Array();
for (k = 0; k < formElement.length; k++) {
tmpArray = formElement[k].split("=");
nameValue[tmpArray[0]] = tmpArray[1];
}
}
return nameValue
}

var srchData = decodeSearchString();
</SCRIPT>
</head>

<body>

<form name="myform" method="post" action="">
<SCRIPT LANGUAGE="JavaScript1.2">
<!--
document.write("Email: " + srchData.Email);
document.write("<br>");
document.write("ID: " + srchData.ID);
document.write("<br>");
document.write("Name: " + srchData.Name);
document.write("<br><br>");
//-->
</script>

<input type="submit" value="Submit">
</form>

</body>
</html>

dlg0351
03-17-2005, 04:36 PM
Anyone have any suggestions?

codegoboom
03-17-2005, 06:00 PM
I am able to get the first pass to work but I am not sure what should go in the value of the hidden fields.

What is that supposed to mean?

dlg0351
03-17-2005, 06:35 PM
What do you mean what is that supposed to mean?

codegoboom
03-17-2005, 06:36 PM
exactly :p

dlg0351
03-17-2005, 06:39 PM
Do you have a suggestion to answer my original question?

codegoboom
03-17-2005, 06:47 PM
I suggest that you restate it, because apparently I'm not the only one who doesn't quite understand what it was... ;)

dlg0351
03-17-2005, 07:05 PM
I am trying to pass values from one html page to another using javascript. The code is three different html pages that will be viewed in sequence.

The first page an email address is entered in an input box and an id is stored and passed to the second page.

The second page the email address and id or displayed and an input is there for a name to be entered and all three are passed to the third page.

The third page displays all three, email, id and name.

My problem is that I am not sure what goes in the value part of the hidden fields on page two:



<input type="hidden" name="Email" value="???">
<input type="hidden" name="ID" value="???">


Do this explanation help?

codegoboom
03-17-2005, 07:16 PM
Yes, that's understandable--though I don't have an immediate answer.

dlg0351
03-17-2005, 09:01 PM
No problem, thanks for your help.

A1ien51
03-17-2005, 09:27 PM
You are either going to have to use cookies or a query string to pass values from one page to the next.

It would be a lot easier with a server side language.

Eric

dlg0351
03-17-2005, 09:38 PM
If I could use a server side language I would, unfortunately the client I am doing this for down not pay for PHP with their hosting package.

I am not familiar with cookies or query strings, any direction or suggestions for this?

codegoboom
03-18-2005, 01:29 AM
Yeah, here's one: http://tech.irt.org/articles/js063/



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum