skip to Main Content

I have a selectbox named groupFeaturesSelectBox
I set the selected value here :

View Get.cshtml

Javascript side is :

Javascript change event of select box

However it is not triggered !

Change event only triggering when I change the select list value but on page load it is not triggered what is wrong ?

2

Answers


  1. Chosen as BEST ANSWER
    <select class="form-control mb-2" id="groupFeaturesSelect" name="groupFeaturesSelect" required>
        <option value="">--Stok Özelliği Seçiniz--</option>
        @foreach (GroupFeatureDto groupFeature in ViewBag.GroupFeatures)
        {
            if(groupFeature.Id == Model.GroupFeatureId)
            {
                <option value="@groupFeature.Id" selected>@groupFeature.FeatureName</option>
            }
            else
            {
                <option value="@groupFeature.Id">@groupFeature.FeatureName</option>
            }
    
        }
    </select>
    

    Javascript Code :

    $(document).ready(function () {
    $('#groupFeaturesSelect').change(function (event) {
         var featureId = $(this).val();
         $('input[name="groupFeatureId"]').val(featureId);
         LoadFeatureValues(featureId);
     });
    }
    

    This page is update page so I want it come selected when page loads According to the selected value the other selectbox will appear


  2. If the code is not working after Ajax page load, try the following jQuery code

    $('document').on('change','#groupFeaturesSelect',function(event){
         var featuredId = $(this).val();
         $('input[name="featureId"]').val(featuredId);
         LoadfeatureValues(featuredId);
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search