Create checkbox list via Javascript
Description
The following code shows how to create checkbox list via Javascript.
Example
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type="text/javascript"
src="http://code.jquery.com/mobile/1.3.0-beta.1/jquery.mobile-1.3.0-beta.1.js"></script>
<link rel="stylesheet" type="text/css"
href="http://code.jquery.com/mobile/1.3.0-beta.1/jquery.mobile-1.3.0-beta.1.css">
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){<!--from w ww .j av a 2 s . com-->
var listadohtml = '<div data-role="fieldcontain"><fieldset data-role="controlgroup">';
var length = 10;
for (var i = 0; i < length; i++) {
var item = '';
var id = 'id' + i;
item += '<input type="checkbox" name="checkbox-' + id + '" id="checkbox-' + id + '" class="custom" />';
item += '<label for="checkbox-' + id + '"> title' + i + '</label>';
listadohtml += item;
}
listadohtml += '</fieldset></div>';
$('#listaPreguntas').html(listadohtml).trigger('create');
$(document).on('change', '[type=checkbox]', function () {
alert('clicked');
});
});//]]>
</script>
</head>
<body>
<div id="listaPreguntas"></div>
</body>
</html>