How to make disabled or enabled on check box selection using jquery

Posted by kumar on Stack Overflow See other posts from Stack Overflow or by kumar
Published on 2010-06-06T04:33:01Z Indexed on 2010/06/06 4:42 UTC
Read the original article Hit count: 482

Filed under:

Hello Friends,

I am using this code to make enabling or disabling based on checkbox selection

 $('#Pchk').change(function() {
         var che =$('input[name=PMchk]').is(':checked');          
         if(!che)
           {
               $('fieldset').find("input,select,textarea").removeAttr('disabled');
            }
            else
            {
            $('fieldset').find("input:not(:checkbox),select,textarea").attr('disabled', 'disabled');
            $('#genericfieldset').find("input,select,textarea").removeAttr('disabled');
            }
        });

Here is my Fieldset

<fieldset calss="pricingM" id="PricingEditExceptions">
    <div class="fiveper">
    <label>FM#: <span><%=(null != a) ? Model.Asset.FundmasterSec : null%></span></label>
        <label>TNT#:<span><%=(null != a) ? Model.Asset.TNTSecurity: null%></span></label>
        <label>CUSIP#: <span><%=(null != a) ? Model.Asset.CUSIP :null%></span></label>
        <label>Asset:<span><%=(null != a) ? Model.Asset.AssetClassCode: null%></span></label>
         <label>Issue:<span><%=(null != a) ? Model.Asset.IssueType: null%></span></label>
          <label>COQ:<span><%=(null != a) ? Model.Asset.CodeCountryofQuotationName: null%></span></label>
          <label>CCY:<span><%=(null != a) ? Model.Asset.CurrencyCode: null%></span></label>
        <label>&nbsp;</label>
     </div>
     <div class="fiveper" id="display">   
         <input id="Pchk" type="checkbox" name="PMchk" value="<%=Model.ExceptionID%>" />
        <label>ID#: <span><%=(null != a) ? Model.ExceptionID : 0%></span></label>
        <label for="ExceptionStatus">
            Status: <span id="gui-stat-<%=Model.ExceptionID %>">
                <%=Model.LookupCodes["C_EXCPT_STAT"].FirstOrDefault(model => model.Key.Trim().Equals(Model.ExceptionStatus.Trim())).Value%></span>        
        </label>
         <label for="ResolutionCode">
            Resolution:
            <span>
            <%=Html.DropDownListFor(model => model.ResolutionCode, new SelectList(Model.LookupCodes["C_EXCPT_RESL"], "Key", "Value", (null != Model.ResolutionCode) ? Model.ResolutionCode.Trim() : Model.ResolutionCode))%>
            </span>
        </label>
         <label for="ReasonCode">
            Reason:
            <span><%=Html.DropDownListFor(model => model.ReasonCode, new SelectList(Model.LookupCodes["C_EXCPT_RSN"], "Key", "Value", (null != Model.ReasonCode) ? Model.ReasonCode.Trim() : Model.ReasonCode))%></span>
        </label>
        <label>Action Taken:<span><%=Html.DropDownListFor(model => model.ActionCode, new SelectList(Model.LookupCodes["C_EXCPT_ACT"], "Key", "Value", (null != Model.ActionCode) ? Model.ActionCode.Trim() : Model.ActionCode))%></span></label>
        <label>&nbsp;</label>
       </div>
        <div class="fiveper">
          <label>Follow-Up:<span class="datepicker-container"><input type="text" id="exc-flwup-<%=Model.ExceptionID %>" name="exc-flwup-<%=Model.ExceptionID %>" value="<%=Model.FollowupDate %>" /></span></label>
        <label>Inqurity #: <span><%=Html.EditorFor(model => model.IOL)%></span>
        </label>
        <label>&nbsp;</label>
        <label>Comment:
           <span>
            <%=Html.TextAreaFor(model => model.Comment, new { })%>
            <%=Html.ValidationMessageFor(model => model.Comment)%>
            </span>
        </label>
        </div>
        <div id="hide" style="display:none">
        <label><span><%=Model.Sequence %></span></label>
        <label><span><%=Model.AssignedId %></span></label>
               <span id="gui-stat-<%=Model.ExceptionID%>">
                <%=Model.LookupCodes["C_EXCPT_STAT"].FirstOrDefault(model => model.Key.Trim().Equals(Model.ExceptionStatus.Trim())).Value%></span>    
                <span>Last Updated:</span>
                <%=Model.LastUpdateUser.StartsWith("ATPB") ? "SYSTEM" : Model.LastUpdateUser%><br />
                <%=Model.LastUpdated%>
                <% if (DateTime.Now.Date == Model.LastUpdated.Value .Date )
                  {%>
                <%=Math.Round((DateTime.Now - (DateTime)Model.LastUpdated).TotalHours, 0)%> hr<%} %>   
                 <p>
       <%=Html.EditorFor(model => model.SequenceDateTimeAsString)%>
        <%=Html.EditorFor(model => model.AssignedId)%>
        <span><%=Html.EditorFor(model => model.Origination)%></span>
    </p>
        </div>
</fieldset>

If I selct Four Users this Fieldset result will come in Four boxes....each box having Checkbox..Initially when the page loads I am disabling

$('fieldset').find("input:not(:checkbox),select,textarea").attr('disabled','disabled');

ok with my Checkbox Change Funtion I am trying to make Enable or disable my Fieldset.. H

here I need to handle Individual Fieldset based on Chekcbox.. right now If I select one check box all Fieldset inpu,select,texarea are making Disabled or Enable..

can anyone tell me how to handle Individual Fieldset on the same page/>

thanks

© Stack Overflow or respective owner

Related posts about jQuery