简体   繁体   中英

Grails, Update Page after deselecting <g:field>

I have ag:field that when pressing enter or deselect it the page needs to refresh it self because i have a value that is calculated by value in the g:field

<g:field type="text" name="amount" pattern="[1-9]*" maxlength="2" value="${Buyer?.amount}"/>

I tired with, but it does not work for some reason

$("#amount").change(function() {
    $("#" + divId).load("/ordering" + "?amount=" + document.getElementById('amount').value)
 }
$("#amount").keydown(function (event) {
    if (event.keyCode === 13) {
        $("#" + divId).load("/ordering" + "?amount=" + document.getElementById('amount').value)
    }
}

I simplified your code a little to provide a complete working example, the following works for me with little changes to your original post.

/views/test/index.gsp

<!doctype html>
<html>
<head>
    <meta name="layout" content="main"/>
    <script>
        $(document).ready(function(){
            var amt = $( '#amount' );
            $( amt ).keydown(function (event) {
                if (event.keyCode === 13) {
                    $( "#myDiv" ).load("/ordering" + "?amount=" + amt.val() )
                }
            });

            $( amt ).change(function() {
                $("#myDiv").load("/ordering" + "?amount=" + amt.val() )
            });
        });
    </script>
</head>
<body>
    <g:field type="text" name="amount" pattern="[1-9]*" maxlength="2" value="${params.amount}"/>
    <div id="myDiv"></div>
</body>
</html>

TestController

def ordering() {
    render( "Amount is ${params.amount}" )
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM