Why would you like to update a textfield with javascript? Why not just
read the cookie on the server-side and say username.setValue(theNameOfTheUserReadFromCookie)?
Also you might want to consider using LoginForm that allows the browser to use remember passwords and usernames for your application.