Open the page in your web browser and inspect (Right click > Inspect Element) the text input field. You'll find that its ID is not
name, but something in the format of
This is because Salesforce does not simply output the ID given for the element in the Visualforce file, but also includes the names of element's parents, from outermost (here the
apex:page) inwards. As a result,
document.getElementsById('name') is failing to select the element.
To fix this, have a look at this post by the wonderful "Uncle" Bob Buzzard, aka Keir Bowden, aka Walter Sobchak. In short, you need to add
Alternatively you could use a selector library such as the one in jQuery, but it looks like it would be overkill for this use case.