I need to add multiple select drop down list in a JSP page, save multiple values into a database in single field, and get a multi-select to display "selected" values when returning to the JSP page.
How is that possible? I am able to save the multiple selected value in a variable, but am not able to save it in a table.
Any help is appreciated in advance.
function AssetDistribution() {
}
function getMultiSelectValue(select) {
return [].reduce.call(select.options, function(values, option) {
option.selected ? values.push(option.label) : null;
return values;
}, []);
}
function showValues(values) {
document.forms[0].custom2.value = values.join(' , ');
}
<select id="custom2" name="custom2" multiple="multiple" runat="server" onchange="AssetDistribution();showValues(getMultiSelectValue(this));">
<option label="PC" id='asset0' value="1000">PC</option>
<option label="Laptop" id='asset1' value="1200">Laptop</option>
<option label="Microsoft office" id='asset2' value="140">MS office</option>
<option label="Software" id='asset3' value="0">Software</option>
<option label="MSDN" id='asset4' value="2400">MSDN</option>
<option label="Mac laptop" id='asset5' value="1900">Mac laptop</option>
<option label="No" id='asset6' value="0">No</option>
<html:text styleClass="verdana9bld" property="custom2" size="10" disabled='true'/>
</select>