Skip to content Skip to sidebar Skip to footer

Append Text Using Jquery From Checkboxlist

I am working in ASP.NET project. And my task is to append the Checkbox text to the TextBox. Checkboxes's text are bound from Database values in CheckBoxList. protected void prbtn_C

Solution 1:

I guess this snippet helps you out:

$(function() {
	$('input[type="checkbox"]').change(function() {
		// Reset output:
		$("#output").html('');
		
		// Repeat for all checked checkboxes:
		$('input[type="checkbox"]:checked').each(function(){ 
			
			// Get values:var existingText = $("#output").html();
			var textToAppend = $(this).val();
			
			// Append seperator (';') if neccessary:if(existingText != '')
			{
				existingText = existingText + ";";
			}
			
			// Print out append value:
			$("#output").html(existingText + textToAppend);
		});
	});
});
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><h2>Select:</h2><inputtype="checkbox"value="Jan"/>Jan
<inputtype="checkbox"value="Feb"/>Feb
<inputtype="checkbox"value="Mar"/>Mar
<inputtype="checkbox"value="Apr"/>Apr

<h2>Output:</h2><divid="output"></div>

Solution 2:

 $(document).ready(
    $('.checkBoxCommunClass').on('click', function () {
        var id = $(this).get(0).id;
        if ($('input[id=' + id + ']:checked').length > 0)
            $('#resultTextInput').val() = $('#resultTextInput').val() + $(this).val();
    }));

Post a Comment for "Append Text Using Jquery From Checkboxlist"