简体   繁体   中英

Retrieving g:select value from within gsp - No form

How does one pass the value of the g:select box in a link action:

<g:select name="sel.n" from="${personList}" value="" />
<g:link action="addValue" params="${[personID: personInstance.id, selectionVal: sel.n.value]}">Add</g:link>

How do I retrieve the value of the selection box sel.n to pass in that action link?

This is NOT a form.

You'll want to use jQuery for something like this. Below is a sample that should get you started down the right path.

var val = "";
$('#sel\\.n').change(function() {

    val = $(this).text();

    $("a").attr('href', function(i, h) {
            return h + (h.indexOf('?') != -1 ? "&" : "?") + "selectValue="+val;

    });
});

The above code will catch when the select box changes and then alters the query string of the href link. If your unfamiliar with jQuery you'll need to run through some basics it's an essential tool for things like this. Good luck and enjoy!

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