Skip to Content
author's profile photo Former Member
Former Member

Submit a form using keyboard Return/Enter

Hi,

I am looking for an equivalent of Submit button in HTMLB.

I need to submit the form when the user hits on the Return/ Enter from Keyboard. I am using HTMLB buttons on my JSP.

Does anyone know how to do this?

Thanks

Lakshmi

Add comment
10|10000 characters needed characters exceeded

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Jun 03, 2004 at 05:48 PM

    Try the following :

    When you create the input field(s) add a javascript event listener

    InputField inf2 = new InputField("myInput");

    // Enable JavaScript object generation for access in JavaScript

    inf2.setJsObjectNeeded(true);

    inf2.setClientEvent(EventTrigger.ON_KEYUP, "checkForSubmit(this,event)");

    (I am not sure if the parameters for the javascript method works)

    Then add a javascript method :

    function submitenter(myfield,e)

    {

    var keycode;

    if (window.event) keycode = window.event.keyCode;

    else if (e) keycode = e.which;

    else return true;

    if (keycode == 13)

    {

    //add code to submit the form

    //left as an exercise to the user

    return false;

    }

    else

    return true;

    }

    This should at least get you started

    Add comment
    10|10000 characters needed characters exceeded