Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everybody,

I want to show how many checkboxes are checked. This is my partial view, where a user can select the selectboxes:

C#
div id="tabs">
    <ul>
        <li><a href="#tabs-1">Personal information</a></li>
        <li><a href="#tabs-2">Profile Photo</a></li>
        <li><a href="#tabs-3">Other Photos</a></li>
        <li><a href="#tabs-4">Climb</a></li>
        <li><a href="#tabs-5">route</a></li>
    </ul>
    <div id="tabs-1">
        @Html.Partial("_GetUserProfile", Model)
    </div>
    <div id="tabs-2">
        @Html.Partial("_GetProfilePicture", Model)
    </div>
    <div id="tabs-3">
        @Html.Partial("_GetOtherImages", Model)
    </div>
    <div id="tabs-4">
        @Html.Partial("_GetClimbTab", Model)
    </div>

    <div id="tabs-5">
        @Html.Partial("_GetRouteTab", Model)
    </div>

</div>

@section Scripts
{
    <link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.11.0.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.form.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui-1.10.4.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/bootstrap-filestyle.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.form.min.js")" type="text/javascript"></script>

    <script>
       
        $(document).ready(function () {
           
            var numSelected = $("input.mycheckBox:checked").length;
                alert(numSelected)
            


              
            });


and so this works, you will see how many checkboxes are selected.

but how many checkboxes have to been seen by a other partial view, like this(detail.cshtml):

C#
<div id="tabs">
    <ul>
        <li><a href="#tabs-1">Profile</a></li>
        <li><a href="#tabs-2">Photos</a></li>
        
    </ul>
    <div id="tabs-1">
        @Html.Partial("_GetDetailsProfileTab", Model)
    </div>
    <div id="tabs-2">
        @Html.Partial("_GetDetailsPhotoTab", Model)
    </div>
 

</div>



@section Scripts{

    <link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />   
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/Progressbar.css")" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/jquery-ui-1.10.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Progressbar.js")" type="text/javascript"></script>






    <script>

        $(document).ready(function () {

            var numSelected = $("input.meter:checked").length;
            alert(numSelected)




        });


because this is the detail view, where the user can see all the other users and also which user selected which checkboxes.

and this is for example part of the the _GetDetailsProfileTab view:


C#
<div>
        <div class="table-responsive">
            <table class="table table-striped table-bordered">
                <tr>

                    <th><h4>Climbs</h4><div id="progressBar" class="climbsName"><div></div></div></th>

                </tr>
               
                <tr>

                    <td>
                        <table width="550">
                            <tr>
                                <td><h6>NAME</h6></td>

                                <td><h6>COUNTRY</h6></td>

                                <td><h6>DIFFICULT LEVEL</h6></td>

                            </tr>



                            @{
                                foreach (var climb in Model.Climbs)
                                {

                                   
                                    <tr>
                                        <td>@climb.Name</td>

                                        <td>@climb.country.country_name </td>

                                        <td>@climb.difficult.DifficultName</td>

                                    </tr>
                           


                                }
                            }
                        </table>

                       

                    </td>

                </tr>



            </table>

        </div>
    </div>


the user can then see by an other profile wich checkboxes are selected.

But in the Details.cshtml file if you use this:

C#
$(document).ready(function () {

           var numSelected = $("input.meter:checked").length;
           alert(numSelected)




       });


this does not work anymore.if gives everytime 0

Thank you
Posted
Updated 21-Mar-15 6:36am
v3

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