开发者

How to assign value of a text box to Grails link tag's id?

I have a textbox on my page that ppl can input numbers, by clicking the button "submit" I want it to be the same as clicking 开发者_如何学Cthe id in the list, which would redirect to the show page. How can I do that?

<g:link action="show" id="<g:javascript>document.getElementById('TextBox').value()</g:javascript>">
   <input type="button" class="bigbuttonstyle" value="Submit" name="Submit" /></div>
</g:link>

Above won't work... but that's something i want... please advise. Thanks!!


That won't work because when the link tag renders HTML, it uses the ID attribute to build the URL. I would just use some behavioral JavaScript to bind a click event to your button that would issue a redirect for you. So using something like jQuery it would look a little like this...

<button id='show-btn'>Show</button>

$(function() {
   $('#show-btn').click(function() {
      window.location = '/path/to/show/' + $('#TextBox').val();
   });
});

What's nice about this also is that you get to remove inline JavaScript out of your markup which is becoming an anti-pattern.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜