Skip to content
Loading
  1. $("#btnAdd").click(function(){  
  2.  $("#dllStatus").prop("disabled", true);  // check Id is correct if inside master page use [id^='ddlstatus']
  3. $("#modal_form_horizontal").modal('show');  
  4. });  
 
+2
  • Vishal Yelve
    +2

    Try this to disable dropdown on Button click 

    $("#ddlStatus").attr("disabled", "disabled");

    +2
  • +2
    Hi Vishal
     
       Where i should write your code
     
    Thanks 
    +2
  • Vishal Yelve
    +2
    Hi Ramco,
     
    Try this 
     
    1. "text/javascript">    
    2.     $(document).ready(function () {           
    3.         $("#ButtonID").click(function () {    
    4.             $("#ddlStatus").attr("disabled", "disabled");  
    5.         });    
    6.     });    
    7.     
    8.   
    9. ------------------------ OR  
    10.   
    11. "text/javascript">    
    12.     $(document).ready(function () {           
    13.         $("#ButtonID").click(function () {    
    14.            $('#ddlStatus').prop('disabled', true);  
    15.         });    
    16.     });    
    17.     
     
    +2
  • Satya Karki
    +2
    Hi Ramco, you need to use JavaScript. Below is a sample HTML code on how to do that.

    1. @model Sample.ASPDotNETCore.Models.StudentModel  
    2.   
    3. @{  
    4.     ViewData["Title"] = "CreateStudent1";  
    5. }  
    6.   
    7. "text/javascript">  
    8.     function submitStudent() {  
    9.         var data = {  
    10.             Name: $("#name").val(),  
    11.             Email: $("#email").val(),  
    12.             Phone: $("#phone").val()  
    13.         }  
    14.         console.log(data);  
    15.         $.ajax({  
    16.             type: 'POST',  
    17.             url: '/Home/AddStudent',  
    18.             contentType: 'application/json; charset=utf-8',  
    19.             data: JSON.stringify(data),  
    20.             success: function (result) {  
    21.                 alert('Successfully received Data ');  
    22.                 console.log(result);  
    23.                 $("#ddlBranch").attr("disabled", true);//disable dropdown  
    24.             },  
    25.             error: function () {  
    26.                 alert('Failed to receive the Data');  
    27.                 console.log('Failed ');  
    28.             }  
    29.         })  
    30.     }  
    31.   
    32.       
    33.   
    34.   
    35. Add Student Deatils with dropdown disable using Ajax Post without Form Serialization
        
    36.   
    37. class="row">  
    38.     class="col-md-4">  
    39.         "studenteForm" novalidate class="needs-validation">  
    40.             "ModelOnly" class="text-danger">
      
  •             class="form-group">  
  •                 for="Name" class="control-label">  
  •                 for="Name" class="form-control" id="name" required />  
  •                 for="Name" class="text-danger">  
  •               
  •             class="form-group">  
  •                 for="Email" class="control-label">  
  •                 for="Email" type="email" class="form-control" id="email" />  
  •                 for="Email" class="text-danger">  
  •               
  •             class="form-group">  
  •                 for="Phone" class="control-label">  
  •                 for="Phone" class="form-control" id="phone" />  
  •                 for="Phone" class="text-danger">  
  •               
  •               
  •             class="form-group">  
  •                 "ddlBranch" class="m-b-sm  w-lg form-control" onchange="ViewHistoricData()">  
  •                     "ALL" selected="selected">ALL  
  •                     "First">First Item  
  •                      "Second">Second  
  •                   
  •               
  •   
  •             class="form-group">  
  •                 "button" id="submit" class="btn btn-primary" onclick="submitStudent()">Add   
  •               
  •   
  •           
  •       
  •   
  •   
  • @section Scripts {  
  •     @{  
  •     await Html.RenderPartialAsync("_ValidationScriptsPartial");  
  • }  
  • }  
  • +2