JSFiddle - React, Tailwind, and code Playground
by martinschaer
HTML
<form id="theform" action="#">
<ul>
</ul>
</form>
JavaScript
var span = '<span id="valuespan">This is the value of a text box</span>';
var value = $(span).text();
var id = $(span).attr('id');
var field = '<input type="checkbox" name="' + id + '" id="' + id + '" value="' + value + '" />';
field += '<label for="' + id + '">' + value + '</label>';
$('#theform ul').append('<li>' + field + '</li>');
// just to make sure the value was correctly set when you check the checkbox
$('#' + id).change(function(){alert('value = ' + $(this).val())});