View Full Version : Passing values between html pages
y1k2h3
11-30-2006, 02:44 AM
I'm developing a prototype website. NO server interaction or anything.
I just want to pass the keyed in data around from HTML pg1 to HTML Pg2.
Any ideas..
thetestingsite
11-30-2006, 02:48 AM
You could use javascript to place cookies in the users browser for use on the pages. How you would pull this off, I'm not sure but maybe someone with javascript know-how could inform us both.
y1k2h3
11-30-2006, 02:53 AM
u means using document.cookie??
thetestingsite
11-30-2006, 02:54 AM
Perhaps, if that is the javascript way of doing it. (I'm only used to using PHP for interaction and am currently in the process of learning Javascript and AJAX.) I'm pretty sure this is the best way to do it without server side interaction.
y1k2h3
11-30-2006, 03:03 AM
:D Yup, i found it. Just wonder if it can store array. v
http://www.dynamicdrive.com/forums/showthread.php?t=13504&highlight=document.cookie
codeexploiter
11-30-2006, 03:59 AM
Another method for passing the values between page is as follows. you can use the HTML form field too to pass the values between pages
The first page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<a href='2.htm?Something=This is another method'>Click here</A>
</body>
</html>
The page that gets the parameter from the first page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<SCRIPT LANGUAGE="Javascript">
function GetParam(name)
{
var start=location.search.indexOf("?"+name+"=");
if (start<0) start=location.search.indexOf("&"+name+"=");
if (start<0) return '';
start += name.length+2;
var end=location.search.indexOf("&",start)-1;
if (end<0) end=location.search.length;
var result=location.search.substring(start,end);
var result='';
for(var i=start;i<=end;i++) {
var c=location.search.charAt(i);
result=result+(c=='+'?' ':c);
}
return unescape(result);
}
alert(GetParam('Something'));
</SCRIPT>
</body>
</html>
The above mentioned Javascript can be described fully at http://www.cryer.co.uk (http://www.cryer.co.uk/resources/javascript/script8.htm)
djr33
11-30-2006, 08:04 AM
Yeah. Using a variable in the address bar makes the most sense.
I would suggest using PHP for this purpose. It's much better.
But... javascript doesn't need a server. That is the ONLY advantage, but if you need that, then that's the only real option.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.