I would like to call function on backingbean only if the user press the enter
key. But it doesn't work. On Chrome's console, it's always returns: Uncaught TypeError: object is not a function
everytime I press any button. What's wrong with the code? Thanks.
<p:inputText id="txtValue" value="#{cc.attrs.value}" onkeyup="onkeypress()">
</p:inputText>
<script type="text/javascript">
function onkeypress() {
if(event.keyCode==13) {
alert("true");
} else {
alert("false");
}
}
</script>
<p:remoteCommand name="rc" actionListener="#{cc.onKeyPress}" out="count" />
add parameter to your onkeypress
function would fix your problem
<script type="text/javascript">
function onkeypress(event) {
if(event.keyCode==13) {
alert("true");
} else {
alert("false");
}
}
</script>