I have two g:select comboboxes that I want to add to the multiple select list when clicking an image.
Here is the function in javascript:
function addToList(list,firstOpt, secOpt)
{
var y = document.createElement('option');
y.text = firstOpt + ' - ' + secOpt;
y.value = firstOpt+'-'+secOpt;
var elSel = document.getElementById(list);
try {
elSel.add(y, null); // standards compliant; doesn't work in IE
}
catch(ex) {
elSel.add(y); // IE only
}
}
I think the problem is here in the actual button:
<img src="${resource(dir:'images',file:'arrow.png')}" onclick="addToList('BList','first','second')"/>
when I click it, “first – second” gets added to the list, not the actual value of the g:select boxes. I also tried ${first} and ${second} but had no luck.
Any help is greatly appreciated, thanks!
You don’t have any code in there that retrieves the values of the first and second select lists.
You would probably need something like this:
You might then use this with the following selects: