D Infosystems
D Infosystems

Reputation: 524

How to insert checkbox checked value to textbox without autopostback

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.

and if i uncheck checkbox1 and checkbox2 then value in textbox is blank

Upvotes: 0

Views: 1937

Answers (1)

Phil.Wheeler
Phil.Wheeler

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

Related Questions