Horje
html onchange call js function Code Example
html onchange call js function
<select name="region_id" class="form-select" required onChange="getDistricts(this);">
                                <option value="">-----------</option>
                                @foreach($regions as $region)
                                    <option value="{{ $region->id }}" {{ old('region_id', '') == $region->id ? 'selected' : '' }}>{{ $region->name_ru }}</option>
                                @endforeach
                            </select>

<script>
        function getDistricts(region_id) {
            var value = region_id.value;
            $.ajax({
                url: '/api/region/getDistricts/' + value,
                type: "GET",
                dataType: "json",
                success: function (data) {
                    var html = '';
                    $.each(data, function (key, value) {
                        html += '<option value="' + value.id + '">' + value.name_ru + '</option>';
                    });
                    $('select[name="district_id"]').html(html);
                    $('select[name="district_id"]').removeAttr('disabled');
                }
            });
        }
    </script>
html onchange call js function
//Change the onchange to onChange="checkit(this); 
//and then something like the below in checkit

function checkit(selectObj)
{ 
  var idx = selectObj.selectedIndex;
  document.frm.Month.disabled = idx == 0;
}




Javascript

Related
javascript get random items from array Code Example javascript get random items from array Code Example
JavaScript how do you create a screen button in 10 lines? Code Example JavaScript how do you create a screen button in 10 lines? Code Example
JavaScript does not protect the property name hasOwnProperty Code Example JavaScript does not protect the property name hasOwnProperty Code Example
equivalent of useHistory in react Code Example equivalent of useHistory in react Code Example
javascript check if date is less than today Code Example javascript check if date is less than today Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9