jwlarson3rd has asked for the wisdom of the Perl Monks concerning the following question:

I have a form written in cgi.pm. I would like when the page loads that the blinking cursor is in the top textbox called required-name. the code is trying to take advantage of onLoad handler it doesn't work.any help would be appreciated John Larson
print $q->start_html(-title=>'Contact about renting space', -BGCOLOR=>'#FFFFCC', -COLOR=>'#003300', -onLoad=>"window.document.mailform.required-name.focus()");

Replies are listed 'Best First'.
Re: javascript perl cgi.pm
by japhy (Canon) on Jan 31, 2004 at 00:40 UTC
    I'd suggest renaming your textbox. The hyphen is confusing JavaScript. It thinks you're subtracting name.focus() from window.document.mailform.required, because the hyphen is treated like a minus.

    Either change the field name, or do: window.document.mailform.elements['required-name'].focus() (untested)

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
      thank you that works. John Larson