Reputation: 524
I have unlimited asp.net checkboxes to my webpage .How to insert checkbox checked value to textbox without autopostback.
I i check checkbox1 and checkbox2 then in textbox it appear as 1,2 ...and after when i uncheck checkbox1 then in textbox the value would be 2.
Upvotes: 0
Views: 1937
Reputation: 16848
You'd have to use JavaScript to set the value of the textbox, but this obviously wouldn't be posted back to the server or otherwise persisted until your page was eventually submitted.
Let's assume you're using jQuery for your JavaScript library. The following example seeks out all checkboxes and when any are clicked, the textbox will be updated with the ID values of all currently-checked inputs.
$('input:checkbox').click(function(){
var result = $(':checkbox:checked').map(function() {
return this.id;
}).get().join(',');
$('#myTextControl').val(result);
});
Upvotes: 1