What am I doing wrong?
The script i'm trying to write consist of asking the user for his name in a form format which is then sent in a cookie. When the user reconnect to the same page, it displays : Hi, "HISNAME", welcome to my site! I don't know what I'm doing wrong, seriously.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
if ( ! get_cookie ( "username" ) )
var username = document.write(
<input type="text" name="texte" value="">
<INPUT TYPE="button" NAME="bouton" Value="Click" onClick="testResults(this.form)">
if ( username )
var current_date = new Date;
var cookie_year = current_date.getFullYear ( ) + 1;
var cookie_month = current_date.getMonth ( );
var cookie_day = current_date.getDate ( );
set_cookie ( "username", username, cookie_year, cookie_month, cookie_day );
var username = get_cookie ( "username" );
document.write ( "Hi " + username + ", welcome to my website!" );
document.location.reload ( );\">
Forget about me!</a>" );
Where are these get_cookie and set_cookie functions defined, also the way you are writing out the <form> using document.write looks incorrect?
Last edited by thraddash; 01-26-2011 at 04:48 PM.
Everything in document.write needs to be in between the ( and ) on one line, and needs to be surrounded by " and ", which things like name="name" would break.
You could set a var thisContent = ""; then use the shortcut for appending the data and split it up across several lines, then document.write(thisContent);
var thisContent = "";
thisContent += "blah blah blah blah";
thisContent += "bleh bleh bleh bleh";
// and escape the "
thisContent += "<input name=\"name\" />";
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)