I would like to convert my current code to a dynamic checkbox. can anyone help me?
<select id="genre" name="genre">
<option value="">-Select-</option>
<select name="category" id="category" multiple="multiple">
<option>-Select-</option>
var options= {
val1:'option1',
val2:'option2',
val3:'option3',
val4:'option4',
}
$('#genre').change(function(){
$('#category').children().remove().end().append('<option>-Select-</option>');
if($('#genre').val() == 'Traditional'){
$.each(traditionalOptions, function(val, text) {
$('#category').append( new Option(text,text) );
});
Are you looking for something like this:
jsfiddle
I took the liberty of changing the options so they each have a value that can be different than the displayed text. There’s a lot of different ways to generate DOM elements with jQuery. I went with concatenating a long string of html. I also placed a “label” element around each checkbox since they should always have one.