문제

I have the following in my shop.gsp file:

<input type="text" class="inputTextBox" name="queryString"/>
<g:link action="shop" controller="item" params='[queryString:
"${document.getElementById('queryString').value}", queryType: "search"]'>
 Search
 </g:link>

But in my controller when I do a params.queryString it returns an empty string.I know I could be using a form for this but for my problem I need to use the link like it is. So how can I get the value of my input text in the link parameters?

도움이 되었습니까?

해결책

Here is an example of how to do this with the use of some jQuery. Off the top of my head, so please forgive any typos.

<input id="field" name="field" type="text" value="" />
<g:link class="mylink" controller="somewhere" action="something">My link</g:link>

<script type="text/javascript">
jQuery(function(){
    $("a.mylink").on("click", function(e) {
        window.location.href = $(this).attr("href") + "?field=" + $("#field").val();
        return false;
    });
});
</script>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top