“HTML OnChange Call JS Función” Código de respuesta

HTML OnChange Call JS Función

<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>
Shadow

HTML OnChange Call JS Función

//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;
}
Shadow

Respuestas similares a “HTML OnChange Call JS Función”

Preguntas similares a “HTML OnChange Call JS Función”

Más respuestas relacionadas con “HTML OnChange Call JS Función” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código