locked
enable disable textbox based on selection - jquery RRS feed

  • Question

  • User181930479 posted

    im trying to enable disable textboxes based on drop down selection , but its NOT working , and im NOT getting any errors in chrome browser code debugger , any suggestion , below is my code 

      <script  src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
        
    
        <script>
    
    
    
    
            var $state = $('#SelectpaymentType'),
        $txtBankName = $('#txtBankName');
            $state.change(function () {
                if ($state.val() == 'شيك') {
                    $txtBankName.removeAttr('disabled');
                } else {
                    $txtBankName.attr('disabled', 'disabled').val('');
                }
            }).trigger('change');
    
    
        </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
       
        
                   <div style="text-align:right !important;" class="form-group col-sm-12">
          <label  class="control-label" for="sel1">payment option</label>
          <select  class="form-control"  id="SelectpaymentType" name="SelectpaymentType" runat="server">
               <option>select option from below</option>
           <option   value="E-p">E-p</option> 
            <option  value="شيك">شيك</option>
            <option  value="cash">cash</option>
           
          </select>
     
             </div>
            <br />
            <br />
    
              <br />
                             <hr />
                             
                                          
    
    
                              <div class="form-group has-success has-feedback">
            <div>
                 <label class="control-label col-sm-2"" >bank name</label>
            <asp:TextBox ID="txtBankName" runat="server"  class="form-control"  />
          
          </div>
         
          
        </div>
    
    
        </form>
    </body>

    Friday, April 20, 2018 10:02 AM

Answers

  • User-369506445 posted

    hi

    when you want use jquery , you must put in $(function())

    please try below code :

    <!DOCTYPE html>
    <html >
    <head runat="server">
        <title></title>
        
        <script  src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
        <script>
            $(function() {
                var $state = $('#SelectpaymentType'),
    $txtBankName = $('#txtBankName');
                $state.change(function () {
                    if ($state.val() == 'شيك') {
                        $txtBankName.removeAttr('disabled');
                    } else {
                        $txtBankName.attr('disabled', 'disabled').val('');
                    }
                }).trigger('change');
    
            });
    
     
    
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
       
        
                   <div style="text-align:right !important;" class="form-group col-sm-12">
          <label  class="control-label" for="sel1">payment option</label>
          <select  class="form-control"  id="SelectpaymentType" name="SelectpaymentType" runat="server">
               <option>select option from below</option>
           <option   value="E-p">E-p</option> 
            <option  value="شيك">شيك</option>
            <option  value="cash">cash</option>
           
          </select>
     
             </div>
            <br />
            <br />
    
              <br />
                             <hr />
                             
                                          
    
    
                              <div class="form-group has-success has-feedback">
            <div>
                 <label class="control-label col-sm-2" >bank name</label>
            <asp:TextBox ID="txtBankName" runat="server"  class="form-control"  />
          
          </div>
         
          
        </div>
    
    
        </form>
    </body>
    </html>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 20, 2018 11:01 AM