No, the backslash trick will *NOT* work.
HTML does *NOT* pay attention to \" as anything special.
To HTML you would have
<body onload="document.forms[\" formname\ "].NAME.focus()">
The first answer is okay, but the preferred way in modern XHTML is
because (a) all tag names and attributes should be lower case and (b) all attribute values should be given in true "..." quotes, not '...'.
Though even that is obsolescent as named forms are considered out of date. You should, instead, give the form an ID and then do