FAQ
Hi,

I have several buttons in my JSF form page. There are also several
input fields. What I would like is when the user is in one particular
text field and hits Enter, I want to trigger the button associated
with it. If I'm in another text field, it should trigger a different
button.

Basically I want to change submit button focus with javascript or JSF
depending on which input field has focus. What is the best way to do
this?

-Steve

Search Discussions

  • Korhonen, Kalle at Jun 10, 2005 at 4:24 pm
    An html form can have only one actual submit button, so make sure you
    have a separate form for each group of input fields and the associated
    submit button.

    Kalle
    -----Original Message-----
    From: steve rock
    Sent: Thursday, June 09, 2005 7:07 PM
    To: users@myfaces.apache.org
    Subject: I have several buttons within a form, depending on
    which part of form they are on, want the Enter key to trigger
    different buttons

    Hi,

    I have several buttons in my JSF form page. There are also
    several input fields. What I would like is when the user is
    in one particular text field and hits Enter, I want to
    trigger the button associated with it. If I'm in another text
    field, it should trigger a different button.

    Basically I want to change submit button focus with
    javascript or JSF depending on which input field has focus.
    What is the best way to do this?

    -Steve
  • Slawek at Jun 11, 2005 at 2:35 pm
    i have answered You yesterday but i cant see my mail, so i do it again...

    the idea is to detect enter key and than "click" desired button

    first we need JS function:

    function keyUpOnSearchEdit(key, buttonId){
    if ( ! key ){//browser dependend sh!t;)
    key = event.keyCode;
    }
    if(key==13){//13 is enter key code
    document.getElementById(buttonId).click();//click on desired
    button
    return false;//important! to stop event propagation
    }
    }


    than we need input text:
    <h:inputText value="#{offerForm.textToSearch}" id="textToSearch" size="30"
    onkeypress="return /*return in important to stop event propagation*/
    keyUpOnSearchEdit(event.which,'f:searchButton')" />

    and finally we need button:

    <x:commandButton value="#{msg.SEARCH_BUTTON}" action="#{offerForm.search}"
    id="searchButton"/>


    cheers

    Slawek

    Hi,

    I have several buttons in my JSF form page. There are also several
    input fields. What I would like is when the user is in one particular
    text field and hits Enter, I want to trigger the button associated
    with it. If I'm in another text field, it should trigger a different
    button.

    Basically I want to change submit button focus with javascript or JSF
    depending on which input field has focus. What is the best way to do
    this?

    -Steve
  • Slawek at Jun 11, 2005 at 2:44 pm
    i have answered You yesterday but i cant see my mail, so i do it again...
    sht strange is going on in my new mail client so im sory if someone was
    spamed by this mail:P




    the idea is to detect enter key and than "click" desired button

    first we need JS function:

    function keyUpOnSearchEdit(key, buttonId){
    if ( ! key ){//browser dependend sh!t;)
    key = event.keyCode;
    }
    if(key==13){//13 is enter key code
    document.getElementById(buttonId).click();//click on desired button

    return false;//important! to stop event propagation
    }
    }


    than we need input text:
    <h:inputText value="#{offerForm.textToSearch}" id="textToSearch" size="30"
    onkeypress="return /*return in
    important to stop event propagation*/
    keyUpOnSearchEdit(event.which,'f:searchButton')" />

    and finally we need button:

    <x:commandButton value="#{msg.SEARCH_BUTTON}" action="#{offerForm.search}"
    id="searchButton"/>


    cheers

    Slawek


    Hi,

    I have several buttons in my JSF form page. There are also several
    input fields. What I would like is when the user is in one particular
    text field and hits Enter, I want to trigger the button associated
    with it. If I'm in another text field, it should trigger a different
    button.

    Basically I want to change submit button focus with javascript or JSF
    depending on which input field has focus. What is the best way to do
    this?

    -Steve
  • Steve rock at Jun 11, 2005 at 3:13 pm
    Perfect, just what I was searching for. I knew there was a way to do
    this with js, just didn't know the keyword event.keyCode to search on.
    Thanks.

    -Steve
    On 6/11/05, Slawek wrote:
    i have answered You yesterday but i cant see my mail, so i do it again...
    sht strange is going on in my new mail client so im sory if someone was
    spamed by this mail:P




    the idea is to detect enter key and than "click" desired button

    first we need JS function:

    function keyUpOnSearchEdit(key, buttonId){
    if ( ! key ){//browser dependend sh!t;)
    key = event.keyCode;
    }
    if(key==13){//13 is enter key code
    document.getElementById(buttonId).click();//click on desired button

    return false;//important! to stop event propagation
    }
    }


    than we need input text:
    <h:inputText value="#{offerForm.textToSearch}" id="textToSearch" size="30"
    onkeypress="return /*return in
    important to stop event propagation*/
    keyUpOnSearchEdit(event.which,'f:searchButton')" />

    and finally we need button:

    <x:commandButton value="#{msg.SEARCH_BUTTON}" action="#{offerForm.search}"
    id="searchButton"/>


    cheers

    Slawek


    Hi,

    I have several buttons in my JSF form page. There are also several
    input fields. What I would like is when the user is in one particular
    text field and hits Enter, I want to trigger the button associated
    with it. If I'm in another text field, it should trigger a different
    button.

    Basically I want to change submit button focus with javascript or JSF
    depending on which input field has focus. What is the best way to do
    this?

    -Steve

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriesmyfaces
postedJun 10, '05 at 2:07a
activeJun 11, '05 at 3:13p
posts5
users3
websitemyfaces.apache.org

People

Translate

site design / logo © 2019 Grokbase