Dynamically create checkbox with JQuery from text input
<div id=”cblist”> <input type=”checkbox” value=”first checkbox” id=”cb1″ /> <label for=”cb1″>first checkbox</label> </div> <input type=”text” id=”txtName” /> <input type=”button” value=”ok” id=”btnSave” /> <script type=”text/javascript”> $(document).ready(function() { $(‘#btnSave’).click(function() { addCheckbox($(‘#txtName’).val()); }); }); function addCheckbox(name) { var container = $(‘#cblist’); var inputs = container.find(‘input’); var id = inputs.length+1; $(‘<input />’, { type: ‘checkbox’, id: ‘cb’+id, value: name }).appendTo(container); … Read more