Get value of multiselect box using jquery or javascript
Posted
by Hulk
on Stack Overflow
See other posts from Stack Overflow
or by Hulk
Published on 2010-03-30T06:53:09Z
Indexed on
2010/03/30
7:03 UTC
Read the original article
Hit count: 571
In the code below, how to get the values of multiselect box in function val() using jquery or javascript.
<script>
function val()
{
//Get values of mutliselect drop down box
}
$(document).ready(function() {
var flag=0;
$('#emp').change(function() {
var sub=$("OPTION:selected", this).val()
if(flag == 1) $('#new_row').remove();
$('#topics').val('');
var html='<tr id="new_row" class="new_row"><td>Topics:</td><td> <select id="topic_l" name="topic_l" class="topic_l" multiple="multiple">';
var idarr =new Array();
var valarr =new Array();
{% for top in dict.tops %}
idarr.push('{{top.is}}');
valarr.push('{{topic.ele}}');
{% endfor %}
for (var i=0;i < idarr.length; i++)
{
if (sub == idarr[i])
{
html += '<option value="'+idarr[i]+'" >'+valarr[i]+'</option>';
}
}
html +='</select></p></td></tr>';
$('#tops').append(html);
flag=1;
});
});
</script>
Emp: <select id="emp" name="emp">
<option value=""></option>
</select>
<div name="tops" id="tops"></div>
<input type="submit" value="Create Template" id="create" onclick="javascript:var ret=val();return ret;">
Thanks..
© Stack Overflow or respective owner