Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

ajax:drop-down remove an d add select option

        <div class="col-xl-2">
                        <label>Family</label>
                        <select name="FamilyID" onchange="getBrandByfamilyId(this.value)" style="width :100%" asp-items="@ViewBag.Families" class="form-control form-control-user">
                            <option value="-1">Please select one</option>
                        </select>
                    </div>
                    <div class="col-xl-2">
                        <label>Brand</label>
                        <select name="BrandID" id="VehicleBrandID" style="width :100%"  class="form-control form-control-user">
                            <option value="-1">Please select one</option>
                        </select>
                    </div>
   
   
     function getBrandByfamilyId(val) {           
            $("#VehicleBrandID").empty();
            var select = document.getElementById('VehicleBrandID');
            var opt = document.createElement('option');
            opt.value = -1;
            opt.innerHTML = "Please select one";
            select.appendChild(opt);
            select.disabled = true;
            if (val > 0) {
                $.ajax({
                    type: "Post",
                    url: "/Vehicle/getBrandByfamilyId",
                    data: { "FamilyId": val },
                    success: function (response) {
                     
                        if (response.status == 1) {
                            
                            $.each(response.object, (i, e) => {
                                var opt = document.createElement('option');
                                opt.value = e.value;
                                opt.innerHTML = e.text;
                                select.appendChild(opt);
                            });
                            select.disabled = false;

                        } else {
                            throwException(response.object);
                        }
                    },
                    failure: function (response) {
                        throwException(response)
                    },
                    error: function (response) {
                        throwException(response)
                    }
                })
            } 
           
        }
Comment

PREVIOUS NEXT
Code Example
Javascript :: json_populate_recordset 
Javascript :: createElement calls without JSX 
Javascript :: cypress contains regex 
Javascript :: let a local variable 
Javascript :: documetn 
Javascript :: merge json data in main.go in golang 
Javascript :: function sleep(delay) { var start = new Date().getTime(); while (new Date().getTime() < start + delay); } 
Javascript :: reset default style javascript 
Javascript :: angular mat-calendar send to form 
Javascript :: how to get csrf token javascript document query selector 
Javascript :: unique in order codewars javascript 
Javascript :: dollar sign brackets javascript 
Javascript :: salman javascript id 
Javascript :: netlify not deploying react site 
Javascript :: firebase ststokenmanager return undefined 
Javascript :: Javascript - The file size is measured in bytes 
Javascript :: e.stopPropagation() is not working as expected 
Javascript :: provider not found react 
Javascript :: return multiple native element react native 
Javascript :: how to bind two ng-content in a component angular 
Javascript :: state changes when changing route useContext next 
Javascript :: how to run the counter when we reach at a specific section in jquery 
Javascript :: como fazer piramade de asteriscos 
Javascript :: links 
Javascript :: raphael js rounded rectangle 
Javascript :: execute function after other has ended js 
Javascript :: discord js ping command 
Javascript :: javascript reduce array of objects group by property 
Javascript :: how to catch shortcut keys in jquery 
Javascript :: nodejs s3 read 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =