i need have multiple values selected when call loaddropdown function. not working.... please suggest how multiple options selected.
<td>select profession:</td> <td> <select name="selectcontent_profession" id="selectcontent_profession" multiple> <option value="0">none</option> <option value="10">student</option> <option value="201">lecturer</option> <option value="333">head of department</option> <option value="421">principal</option> <option value="523">chairman</option> <option value="667">management</option> <option value="784">placement officer</option> </select> </td> <% string s1= "10,333,421,523"; string[] array = s1.split(","); %> <script > function loaddropdown() { <%for(int i=0;i<array.length;i++){%> document.getelementbyid("selectcontent_profession").value ="<%= array[i]%>"; <%}%> } </script>
first have declare select's multiple selection option follows:
<select name="selectcontent_profession" id="selectcontent_profession" multiple="multiple">
and function should this:
var fld = document.getelementbyid('selectcontent_profession'); for(var i=0;i<fld.options.length;i++){ for(var j=0;j<array1.length;j++){ if(fld.options[i].value==array1[j])fld.options[i].selected=true; } }
you trying value of dropdown whereas have set selected.
Comments
Post a Comment