自动填充下拉字段不起作用

时间:2016-10-27 06:57:40

标签: javascript php jquery html

我有两个自动填充的下拉字段。

示例:

  

car_model - > dropdown_field1

     

car_model_variants - > dropdown_field2

当我在car_model字段中选择模型时,car_model_variants必须更新其值。

在我的情况下,我有index.php,您可以在其中单击一个显示模式框的按钮,然后您将找到自动填充的下拉字段。

首次尝试,当选择car_model时,car_model_variants字段正在更新其值。但如果我在car_model_variants为空时提交表单,如果我再次尝试选择car_model,它就不起作用了吗?下拉2字段未更新。以下是我的代码。

(function ($) {
    $('.edit').formPopup({
        'modalParams': {
            'parent_container': $('div.autodeal')
        },
        'callback': function (settings)
        {
            $('.modal')
                    .addClass('large')
                    .css({'z-index': 101});


            $('#used_car_car_model').change(function () {
                var select = $(this);

                $.ajax({
                    'url': '{{ path("autodeal_backend_filter_select") }}',
                    'data': {'carModelId': select.val(), 'carGuideOnly': 0, 'isVerified': 1, 'showCompleteName': 1},
                    success: function (html)
                    {
                        $('#used_car_car_model_variant').html(html);
                    }
                });
            });
        },
        'formSubmitParams': {
            'retainFormUrl': false,
            'submit_callback': function ()
            {
                window.location.reload();
            },
            'error_callback': function (form, settings)
            {
                $('.close, .exit', $(settings.container))
                        .click(function () {
                            window.location.reload();
                        });
            }
        }
    });
})(jQuery);

这是完整的代码。

<form novalidate="" action="/app_dev.php/used-car-listings/164/edit" method="POST">
<div class="marginbottom row gutters">
    <div class="col span_12">
        <div>
            <div>
                <label for="used_car_plate_number" class="required">Plate number</label>                                        
                <input type="text" id="used_car_plate_number" name="used_car[plate_number]" required="required" value="GS0909">
            </div>
            <div>
                <label for="used_car_year" class="required">Year</label>
                <input type="text" id="used_car_year" name="used_car[year]" required="required" value="2015">
            </div>
            <div>
                <label for="used_car_car_model" class="required">Car Model</label>
                <select id="used_car_car_model" name="used_car[car_model]" required="required">
                <option value="">Select A Model</option><option value="102">Mercedes-Benz A-Class</option><option value="401" selected="selected">Mercedes-Benz AMG</option><option value="103">Mercedes-Benz B-Class</option><option value="105">Mercedes-Benz C-Class Coupe</option><option value="104">Mercedes-Benz C-Class Sedan</option><option value="115">Mercedes-Benz CLA-Class</option><option value="576">Mercedes-Benz CLC-Class</option><option value="577">Mercedes-Benz CLK-Class</option><option value="106">Mercedes-Benz CLS-Class</option><option value="107">Mercedes-Benz E-Class</option><option value="578">Mercedes-Benz G-Class</option><option value="108">Mercedes-Benz GL-Class</option><option value="109">Mercedes-Benz GLK-Class</option><option value="110">Mercedes-Benz M-Class</option><option value="111">Mercedes-Benz S-Class</option><option value="112">Mercedes-Benz SL-Class</option><option value="113">Mercedes-Benz SLK-Class</option><option value="114">Mercedes-Benz SLS-Class</option><option value="579">Mercedes-Benz Viano</option></select>
            </div>
            <div>
                <label for="used_car_car_model_variant" class="required">Car Model Variant</label>
                <select id="used_car_car_model_variant" name="used_car[car_model_variant]" required="required"><option value="">Select Mercedes-Benz A-Class Variant</option><option value="343">2014 Mercedes-Benz A-Class A 250 Sport 4MATIC</option><option value="344">2014 Mercedes-Benz A-Class A 45 AMG</option></select>
            </div>
            <div>
                <label for="used_car_mileage" class="required">Mileage</label>
                <input type="text" id="used_car_mileage" name="used_car[mileage]" required="required" value="1700">
            </div>
            <div>
                <label for="used_car_price" class="required">Price</label>
                <input type="text" id="used_car_price" name="used_car[price]" required="required" value="3288300">
            </div>
            <div>
                <label for="used_car_used_car_color" class="required">Color</label>
                <select id="used_car_used_car_color" name="used_car[used_car_color]" required="required">
                <option value="">Select A Color</option><option value="1">Red</option><option value="2">Blue</option><option value="3">Black</option><option value="4">White</option><option value="5">Green</option><option value="6">Silver</option><option value="7" selected="selected">Grey</option><option value="8">Yellow</option><option value="9">Brown</option><option value="10">Beige</option><option value="11">Orange</option><option value="12">Purple</option><option value="13">Pink</option><option value="14">Turquoise</option><option value="15">Bronze</option></select>
            </div>
            <div>
                <label for="used_car_description" class="required">Description</label>
                <textarea id="used_car_description" name="used_car[description]" required="required" cols="4" rows="3">Body color, Tenorite Gray</textarea>
            </div>
            <div>
                <label class="required">City</label>
                <input type="hidden" id="used_car_city_id" name="used_car[city][id]" value="20"><input type="text" id="used_car_city_text" name="used_car[city][text]" required="required" autocomplete="off" value="San Juan, Metro Manila">
            </div>
            <div>
                <label class="required">Is service record submitted</label>
                <div id="used_car_is_service_record_submitted"><label class="marginleft marginright"><input type="radio" id="used_car_is_service_record_submitted_0" name="used_car[is_service_record_submitted]" required="required" value="1">Yes
                </label><label class="marginleft marginright"><input type="radio" id="used_car_is_service_record_submitted_1" name="used_car[is_service_record_submitted]" required="required" value="0" checked="checked">No</label></div>
            </div>
            <div>
                <label class="required">Is LTO verified</label>
                <div id="used_car_is_lto_verified"><label class="marginleft marginright"><input type="radio" id="used_car_is_lto_verified_0" name="used_car[is_lto_verified]" required="required" value="1" checked="checked">Yes
                </label><label class="marginleft marginright"><input type="radio" id="used_car_is_lto_verified_1" name="used_car[is_lto_verified]" required="required" value="0">No
                </label></div>
            </div>
        <div>
    </div>
</div>

<input type="hidden" id="used_car__token" name="used_car[_token]" value="4e4UOHBr5SmtV7Pb0WoWv4xSz90LoVarNG8hw0dy_RY">            <hr class="nomargin marginbottom30 margintop20">
     <div class="row">
        <button type="submit" class="button">Save</button>
     </div>
</form>

0 个答案:

没有答案