Click here to Skip to main content
15,921,452 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have one checkbox in html and I have created multiple checkboxes by putting same checkbox in foreach
for a reference code is a follows.
Question: How I get value of all checkboxes those are checked.
HTML
<div id="friend-list">
    <h3>Grouop Member</h3>               
        <div style="height:190px; width:250px;margin-removed10px; text-align:left " id="Group-list">
 
        <% if (groMoney.Services.UserGroupMemberSevices.get_grpMemberList(groMoney.Services.GroMoneyUserMemberService.getCurrentUser()).Rows.Count != 0)
            {  %>
            <% foreach (System.Data.DataRow MemberData in groMoney.Services.UserGroupMemberSevices.get_grpMemberList(groMoney.Services.GroMoneyUserMemberService.getCurrentUser()).Rows)
               { %>
               <ul>
                   <input id="check-name" type="checkbox" value="<%=MemberData[0]%>" 
                     title="Do you want to select member from group?" name="chk-name" /><%=MemberData[1]%>
               </ul>
            <%} %>
        <%} %>
        </div>
        <div class="lb-content-top">
            <input class="button" style="cursor: pointer;left:20px;top: 2px;" type="button"
                value="View" name="delMember" tabindex="3" title="Delete selection"  önclick="getSelectedMember()" />
        </div>                   
</div>
Posted
Updated 27-Jul-11 6:22am
v4
Comments
Prerak Patel 27-Jul-11 2:02am    
Not clear.

1 solution

I have changed a bit in your code and written a javascript function to find checked value
plz check

function getSelectedMember(field, count)
{
  var icount = document.getElementById(count).value;
  for (var i = 0; i <icount; i++)
  {
    if (document.getElementById(field + i).checked == true)
    {
      alert(document.getElementById(field + i).value);
      //You can use this value
     }
   }
}




XML
<div id="friend-list">
               <h3>Grouop Member</h3>
                    <div style="height:190px; width:250px;margin-removed10px; text-align:left " id="Group-list">
         <% if (groMoney.Services.UserGroupMemberSevices.get_grpMemberList(groMoney.Services.GroMoneyUserMemberService.getCurrentUser()).Rows.Count != 0)
            {int i=0; %> 
            <% foreach (System.Data.DataRow MemberData in groMoney.Services.UserGroupMemberSevices.get_grpMemberList(groMoney.Services.GroMoneyUserMemberService.getCurrentUser()).Rows)
               {%>
               <ul>
                   <input id="check-name<%=i%>" type="checkbox" value="<%=MemberData[0]%>"title="Do you want to select member from group?" name="chk-name" /><%=MemberData[1]%>
               </ul>
            <% i++; //Added} %>
         <%} %>
                    </div>
                   <div class="lb-content-top">
<input type="text" id="txt" value="<%=i%>" style="visibility:hidden" /> //ADDED
                     <input class="button" style="cursor: pointer;left:20px;top: 2px;" type="button" value="View" name="delMember" tabindex="3" title="Delete selection"  önclick="getSelectedMember('check-name', 'txt')" />
                    </div>
             </div>




hope this will help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900