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><ti tle>Problem3</title>
<script type="text/javascript" src="core.js"></script>
<script type="text/javascript">
var FormProblem=
{
init: function()
{
var the_button=docu ment.getElement ById("mybutton" );
Core.addEventLi stener(the_butt on, "click", FormProblem.set Cookie);
Core.addEventLi stener(the_butt on, "click", FormProblem.Red irect);
},
setCookie: function()
{
var name = document.getEle mentById("first field").value;
var age = document.getEle mentById("secon dfield").value;
var color = document.getEle mentById("third field").value;
var the_cookie = "username:n ame/userage:age/favcolor:color; path=..
/newpage.html;"
document.cookie = "my_cookie="+es cape(the_cookie );
},
Redirect: function()
{
window.location .href="newpage. html"
}
};
Core.start(Form Problem)
</script></head>
<body>
<form id="youridentit y">
<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><ti tle>NewPage</title>
<script type="text/javascript">
function readCookie (the_info)
{
if (document.cooki e)
{
var the_cookie = document.cookie ;
var the_cookie = unescape(the_co okie);
var broken_cookie = the_cookie.spli t("mycookie=" );
var the_values = broken_cookie[1];
var broke_again = the_values.spli t("/");
var property_values ="";
for (var loop=0; loop < broke_again.len gth; 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(cook ie_info);
</script></head>
<body>
<script type = "text/javascript">
document.write( "The was someone named"+cookie_i nfo[username]+"at
age"+cookie_inf o[userage]+"who loved the color"+cookie_i nfo[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
"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><ti tle>Problem3</title>
<script type="text/javascript" src="core.js"></script>
<script type="text/javascript">
var FormProblem=
{
init: function()
{
var the_button=docu ment.getElement ById("mybutton" );
Core.addEventLi stener(the_butt on, "click", FormProblem.set Cookie);
Core.addEventLi stener(the_butt on, "click", FormProblem.Red irect);
},
setCookie: function()
{
var name = document.getEle mentById("first field").value;
var age = document.getEle mentById("secon dfield").value;
var color = document.getEle mentById("third field").value;
var the_cookie = "username:n ame/userage:age/favcolor:color; path=..
/newpage.html;"
document.cookie = "my_cookie="+es cape(the_cookie );
},
Redirect: function()
{
window.location .href="newpage. html"
}
};
Core.start(Form Problem)
</script></head>
<body>
<form id="youridentit y">
<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><ti tle>NewPage</title>
<script type="text/javascript">
function readCookie (the_info)
{
if (document.cooki e)
{
var the_cookie = document.cookie ;
var the_cookie = unescape(the_co okie);
var broken_cookie = the_cookie.spli t("mycookie=" );
var the_values = broken_cookie[1];
var broke_again = the_values.spli t("/");
var property_values ="";
for (var loop=0; loop < broke_again.len gth; 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(cook ie_info);
</script></head>
<body>
<script type = "text/javascript">
document.write( "The was someone named"+cookie_i nfo[username]+"at
age"+cookie_inf o[userage]+"who loved the color"+cookie_i nfo[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
Comment