0

I have a input checkboxes in listitems and i need to fetch the selected checkbox text.Below is my html code and i had differentiated the unchecked checkbox with the checked checkbox

<li tabindex="-1" role="option" unselectable="on" class="k-item">//unchecked check box
     <input type="checkbox" name="Type" onclick="Check(event);" class="cbComp" value="40532"> Unselected check box
</li> 

 <li tabindex="-1" role="option" unselectable="on" class="k-item k-state-selected k-state-focused" id="ddlActTypeCompletedKD_option_selected" aria-selected="true">  //checked chekbox
     <input type="checkbox" name="cbCareActType" onclick="onCareActCompletedCheck(event);" 
     class="cbCareActTypeComp" value="40549">Checked checkbox1
 </li>
 <li tabindex="-1" role="option" unselectable="on" class="k-item k-state-selected k-state-focused" id="ddlActTypeCompletedKD_option_selected" aria-selected="true">  //checked chekbox
     <input type="checkbox" name="cbCareActType" onclick="onCareActCompletedCheck(event);" 
     class="cbCareActTypeComp" value="50890">Checked checkbox2
 </li>

Using below code I am getting all the checked checkboxes values in comma separated, but I need to bring the text.

How can I do this?

Text = $('#Addhdn').val(); //I am getting values as 40549,50890 as those both are checked using these values but when i am assigning to text variable ids are going instead i need to send the text $("#ddl").find('.k-input').html(Text); //here i need to bind text instead of ids

<input type="text" id="AddActTypeCompletedhdn" style="display: none;" value='' />

Input will be the values in the hidden field Example -40549,50890 Output should be the text of those values to be displayed as comma seperated in dropdown Expected output- Checked checkbox1,Checked checkbox2

checked two checkboxes but always its binding only one instead it should bind all checked items as comma seperated

testusernew n
  • 13
  • 1
  • 8
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/212006/discussion-on-question-by-testusernew-n-get-the-text-from-input-tag-based-on-val). – Samuel Liew Apr 19 '20 at 10:17

1 Answers1

0
(Html.Kendo().DropDownList() .Name("ddlActTypeCompletedKD").AutoBind(false) .HtmlAttributes(new { style = "width: 228px!important;", id = "ddlActTypeCompletedKD" }) .Template("<input type='checkbox' name='cbCareActType' onClick='onCareActCompletedCheck(event);' class='cbCareActTypeComp' value='#:data.Id#' /><label for='ddlActTypeCompletedKD'> #:data.Name#</label>"))

Change your code top proper html like this and add a label

<input type="checkbox" name="cbCareActType" onclick="onCareActCompletedCheck(event);" 
     class="cbCareActTypeComp" value="40549">
<label for="cbCareActType">Checked checkbox1</label>

and use this to get the value of the label

$("label[for='cbCareActType']").text()
Grumpy
  • 2,140
  • 1
  • 25
  • 38