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

Hi Monks

I have a CGI form consisting of a text box and two buttons. I would like to make it so that if the user presses "enter" on his keyboard when the cursor is in the text box, the lower of the two buttons is activated rather than the upper one that the form appears to be defaulting to.

Any ideas?

TIA

CJ

  • Comment on Changing the default button in a CGI perl script

Replies are listed 'Best First'.
Re: Changing the default button in a CGI perl script
by siva kumar (Pilgrim) on Dec 13, 2006 at 12:45 UTC
    Hi,
    You can use JavaScript. The text box 'onKeyPress' event should call one javascript function that should determine whether keyCode==13(Enter key has been pressed). If keyCode is 13 then enables or disables the buttons using document.formName.buttonName.disabled=false/true.
Re: Changing the default button in a CGI perl script
by olus (Curate) on Dec 13, 2006 at 12:46 UTC
    Actually this is not a Perl question, but still I'll offer my 2 cents.
    In order to achieve what you want, you'll have to play with javascript and capture key down or key press events. Get the code for the key that was pressed and execute the action for the second button if the key is Enter.
Re: Changing the default button in a CGI perl script
by f00li5h (Chaplain) on Dec 13, 2006 at 11:49 UTC

    What are the buttons, and what do they do?

    If they provide any sort of choice, could they perhaps be radio buttons, a check box, dropdown or similar?

    @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;