You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Slawek <ss...@o2.pl> on 2005/03/31 20:14:56 UTC

how to: enter key pressed on inputtext -> commandbutton's action executed?

hi

here is the situation...

page contains:
-input text for typing search string
-command button with action that search typed text
-lots of other command buttons

current scenario:
-user type somme text to inputText
-user takes mouse to hand, click search button, waits, ses result, be 
happy;)
-that works grat;)

situation demanded by boss:
-user type somme text to inputText
-user press ENTER key, waits, see result, bee happy
-should work, but doesnt:/

problem:
if there would be only ONE comand button, than after press eneter key it 
would be default "clicked" (as in html specyfiacation according do submit 
buttons)

but as i have many commandbuttons (html submit inputs), than depends on 
browser ,somme on them is default clicked when presing enter



i tried to do this:

function keyUpOnMyText(key){
	//if key is ENTER (detecting enter works fine) then:
   	document.getElementById('formId:searchButton').click();
}

<h:inputText value=blah onkeyup="keyUpOnMyText(event.which)"/>
<h:commandButton value=blah action=blah id="searchButton"/>
<%/*****  many other buttons *****/%>



but it doesn work as i expected:/
when i press ener then browser propagates default submit action of the 
form (one of other buttons) before my JS function can "click" the search 
button:/

question: how to stop browser from calling submit button when user press 
enter??

slawek

Re: how to: enter key pressed on inputtext -> commandbutton's action executed?

Posted by Heath Borders <he...@gmail.com>.
make the event on your inputText onkeypress instead of onkeyup, and if
the keypress is enter, return false, otherwise return true.

For any javascript eventhandler, returning false cancels the default
action while returning true allows it to occur.


On Thu, 31 Mar 2005 20:14:56 +0200, Slawek <ss...@o2.pl> wrote:
> hi
> 
> here is the situation...
> 
> page contains:
> -input text for typing search string
> -command button with action that search typed text
> -lots of other command buttons
> 
> current scenario:
> -user type somme text to inputText
> -user takes mouse to hand, click search button, waits, ses result, be
> happy;)
> -that works grat;)
> 
> situation demanded by boss:
> -user type somme text to inputText
> -user press ENTER key, waits, see result, bee happy
> -should work, but doesnt:/
> 
> problem:
> if there would be only ONE comand button, than after press eneter key it
> would be default "clicked" (as in html specyfiacation according do submit
> buttons)
> 
> but as i have many commandbuttons (html submit inputs), than depends on
> browser ,somme on them is default clicked when presing enter
> 
> i tried to do this:
> 
> function keyUpOnMyText(key){
>        //if key is ENTER (detecting enter works fine) then:
>        document.getElementById('formId:searchButton').click();
> }
> 
> <h:inputText value=blah onkeyup="keyUpOnMyText(event.which)"/>
> <h:commandButton value=blah action=blah id="searchButton"/>
> <%/*****  many other buttons *****/%>
> 
> but it doesn work as i expected:/
> when i press ener then browser propagates default submit action of the
> form (one of other buttons) before my JS function can "click" the search
> button:/
> 
> question: how to stop browser from calling submit button when user press
> enter??
> 
> slawek
> 


-- 
-Heath Borders-Wing
hborders@mail.win.org