Return to Snippet

Revision: 32556
at September 30, 2010 03:39 by mattvbiggs


Updated Code
<input type="button" id="selectall" value="Select All" /><br />
<input type="button" id="clear" value='<%= ViewData["Label"] %>' />

<script type="text/javascript" language="javascript">
    $(document).ready(function() {
        $('#selectall').click(function() {
            $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', true);
        });
        $('#clear').click(function() {
            $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', false);
        });
    });
</script>


/*If this code is in a user control, it can be called using the following:
(If the codebase is C#:) */
<% Html.RenderPartial("JQuerySelectAll", ViewData["Label"]="Reset"); %>

Revision: 32555
at September 30, 2010 03:35 by mattvbiggs


Updated Code
<input type="button" id="selectall" value="Select All" /><br />
<input type="button" id="clear" value='<%= ViewData["Label"] %>' />

<script type="text/javascript" language="javascript">
    $(document).ready(function() {
        $('#selectall').click(function() {
            $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', true);
        });
        $('#clear').click(function() {
            $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', false);
        });
    });
</script>

Revision: 32554
at September 30, 2010 03:27 by mattvbiggs


Updated Code
<input type="button" id="selectall" value="Select All" /><br />
<input type="button" id="clear" value='<%= ViewData["Label"] %>' />

<script type="text/javascript" language="javascript">
    $(document).ready(function() {
        $('#selectall').click(function() {
            $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', true);
        });
        $('#clear').click(function() {
            $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', false);
        });
    });
</script>

/*If this code is in a user control, it can be called using the following:
(If the codebase is C#:) */
<% Html.RenderPartial("JQuerySelectAll", ViewData["Label"]="Reset"); %>

/*(If the codebase is VB:)*/
<% ViewData("Label") = "Reset"%>    
<% Html.RenderPartial("SelectAllClear", ViewData("Label"))%>

Revision: 32553
at September 28, 2010 23:41 by mattvbiggs


Initial Code
<input type="button" id="selectall" value="Select All" /><br />
<input type="button" id="clear" value='<%= ViewData["Label"] %>' />

<script type="text/javascript" language="javascript">
    $(document).ready(function() {
        $('#selectall').click(function() {
            $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', true);
        });
        $('#clear').click(function() {
            $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', false);
        });
    });
</script>

Initial URL


Initial Description
This is used in combination with JavaScript and MVC (hence the ViewData object). If this code is pasted into a MVC View User Control (.ascx) file, it becomes a reusable Select All/Clear control. It was originally written with a C# codebase. It will work in VB as well, with minor changes (i.e. change all square brackets around ViewData to parenthesis). <br>Also, below the closing script tag is code that is used to call the control. Make sure the string value of the first parameter matches the name of the ascx file that contains the script.

Initial Title
JQuery: Select All/Clear

Initial Tags

 

Initial Language
jQuery