Domanda

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" />
È stato utile?

Soluzione

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>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top