No, the backslash trick will *NOT* work.
Remember, it is HTML that is parsing that, so that it can then invoke JavaScript.
HTML does *NOT* pay attention to \" as anything special.
To HTML you would have
Code:
<body onload="document.forms[\" formname\ "].NAME.focus()">
And it would try to invoke JavaScript with just
The first answer is okay, but the preferred way in modern XHTML is
Code:
<body onload="document.forms['formname'].NAME.focus()">
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
Code:
<body onload="document.getElementById('formid').NAME.focus()">
Again, this all belongs in the JavaScript forum, rather than here.