开发者

Not able to get the selected values from Drop down using jQuery

开发者 https://www.devze.com 2023-03-13 13:57 出处:网络
I\'m trying to add new field to existing gsp page which was written by some other guy. <g:select name=\"clientId\" multiple = \"yes\" size = \"4\" from=\"${com.mycompany.fleet.partymodel.roles.Cl

I'm trying to add new field to existing gsp page which was written by some other guy.

    <g:select name="clientId" multiple = "yes" size = "4" from="${com.mycompany.fleet.partymodel.roles.ClientRole.list()}" class = "filter_combo" optionKey="id" />

and by using jQuery he is getting selected values like this

var selectedclients = "${clientId}";
console.log(selectedclients); // prin开发者_如何学Cts id of selected Clients 

I'm adding new drop down like this in same page

<g:select name="contractId"  multiple = "yes" size = "4" from="${com.mycompany.fleet.rules.Contract.list()}" class = "filter_combo" optionKey="id"/>

and I'm trying to get the selected values using jQuery like this

var selectedcontracts = "${contractId}";

but its not fetching the selected values... am I doing anything wrong here?

What does the ${clientId} mean exactly?


I don't believe that is using JQuery, that is just putting the current value for clientId into the javascript for var selectedclients = "${clientId}"; using standard GSP templating.

ie: when the page is generated, ${clientId} gets replaced with the value in the model

Are you adding contractId to the model in the Controller?

One thing to watch out for here is that if the clientId or contractId has a double quote in them (ie, if clientId was Tim"busy" Yates, then this will generate invalid javascript, as the generated code would look like:

var selectedclients = "Tim "working" Yates" ;

However, if it's just an integer id then I guess this would be ok


How about:

var selectedcontracts = $('select [name="contractId"]').val();
0

精彩评论

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