I'm supposed to develop a page that asks info as form values and when you hit
"submit" it takes you to a page that reads the values you entered into the
first page and displays those values in a message. I can't seem to find where
I'm going wrong. Here's the code:
Setting Cookie and Form Page:
<html><head><title>Problem3</title>
<script type="text/javascript" src="core.js"></script>
<script type="text/javascript">
var FormProblem=
{
init: function()
{
var the_button=document.getElementById("mybutton");
Core.addEventListener(the_button, "click", FormProblem.setCookie);
Core.addEventListener(the_button, "click", FormProblem.Redirect);
},
setCookie: function()
{
var name = document.getElementById("firstfield").value;
var age = document.getElementById("secondfield").value;
var color = document.getElementById("thirdfield").value;
var the_cookie = "username:name/userage:age/favcolor:color; path=..
/newpage.html;"
document.cookie = "my_cookie="+escape(the_cookie);
},
Redirect: function()
{
window.location.href="newpage.html"
}
};
Core.start(FormProblem)
</script></head>
<body>
<form id="youridentity">
<label>Your Name:</label>
<input type="text" name="yourname" id="firstfield"<br>
<label>Your Age:</label>
<input type="text" name="yourage" id="secondfield"<br>
<label>Your Favorite Color:</label>
<input type="text" name="favcolor" id="thirdfield"<br>
<input type="button" value="submit" id="mybutton">
</form>
</body>
</html>
newpage.html:
<html><head><title>NewPage</title>
<script type="text/javascript">
function readCookie (the_info)
{
if (document.cookie)
{
var the_cookie = document.cookie;
var the_cookie = unescape(the_cookie);
var broken_cookie = the_cookie.split("mycookie=");
var the_values = broken_cookie[1];
var broke_again = the_values.split("/");
var property_values="";
for (var loop=0; loop < broke_again.length; loop++)
{
var property_values = broke_again[loop];
var broken_info = property_values.split(":");
var the_property = broken_info[0];
var the_value = broken_info[1];
the_info[the_property] = the_value;
}
}
// Return the info you got passed
return the_info;
}
var cookie_info = {};
cookie_info = readCookie(cookie_info);
</script></head>
<body>
<script type = "text/javascript">
document.write("The was someone named"+cookie_info[username]+"at
age"+cookie_info[userage]+"who loved the color"+cookie_info[favcolor]);
</script>
</body>
</html>
Any idea of where I'm going wrong? I know it's gotta be something simple..
which'll just make me upset that I couldn't find it.
--
Message posted via WebmasterKB.com
http://www.webmasterkb.com/Uwe/Forum...cript/200808/1