quindip: handle onKeyPress event server side (sort of ;-) )

Did you ever need to “catch” a key event? I did! Using the type-ahead feature i wanted to fill some fields depending on the selected value from the type-ahead field.

Now I used the “onBlur” event first. But that would require the user to move the focus away from the field with type-ahead.

I was looking for a solution where immediately after hitting <enter> the fields below would be filled.

Turns out this is pretty easy:

use two onKeyPress event handlers: one client-side, one server-side:

client-side:

if (thisEvent.keyCode==13) {
      return true;
}else{
      return false;
}

server-side:
call whatever functionality you need! in our case it’s a bean populating dependant fields


the client-side piece of code checks for <enter> and calls the server-side functionality only on <enter>

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.