$(document).ready(function() { $("select[id='marka']").change(function() { var marka = $(this).find("option:selected").attr("code"); updateForm(marka,0,0,true); }) $("select[id='model']").on("change",function() { var marka = $("select[id='marka'] option:selected").attr("code"); var model = $(this).find("option:selected").attr("code"); updateForm(marka,model,0,false); }) /* select not-selected */ /* $(".formcredit select").each(function() { var id = $(this).attr("id"); if (id != "marka"&& id!="complect" && id!="model" && $(this).parent().attr("class")!="birthday-picker") { $(this).prepend(""); if ($(".errortext").text().length<20) $(this).val(0); } }); */ /* водительское удосторверение */ $("select[name='form_dropdown_SIMPLE_QUESTION_850']").change(function() { var value= $(this).val(); var udostText = $(".udost-text"); if (value==99) udostText.fadeIn(300); else udostText.fadeOut(300); }); $(".sub_field_trigger").click(function() { $("#hid_block2").toggle(); }) $("input.inputphone").mask("+9(999)999-99-99",{placeholder:"_"}); $("input.phone-country-code").mask("+9",{completed:function(){$(this).parent().find(".phone-city-code").focus();splitPhones($(this).parent())},placeholder:"_"}); $("input.phone-city-code").mask("999",{completed:function(){$(this).parent().find(".phone-num").focus();splitPhones($(this).parent())}, placeholder:"_"}); $("input.phone-num").mask("9999999",{completed:function(){splitPhones($(this).parent())},placeholder:"_"}); $(".formcredit form").submit(function() { var flag = $("input[name='confirmed']").is(":checked"); if (!flag && $("input[name='confirmed']").length>0 ) { alert("Для оформления заявки необходимо согласиться с условиями и политикой конфиденциальности"); return false; } }) }) function splitPhones(compositephone) { var fullphone = true; var i=0; var splitter = "-"; var fullphonestr = ""; $(compositephone).find("input[type='text']").each(function(){ if (this.value.indexOf("_")>-1 || this.value.length==0 ) fullphone = false; if (i==0) fullphonestr+=this.value; else fullphonestr+=splitter+this.value; i++; }); if (fullphone) $(compositephone).find(".all-phone").val(fullphonestr); else $(compositephone).find(".all-phone").val(""); } function updateForm(marka,model,complect, updateModel) { var picture = $(".model_picture"); $.get("/bitrix/ajax/avto.php",{command:"models",model:model,marka:marka},function(data) { try { var select_model = $("select[id='model']"); var select_complect = $("select[id='complect']"); select_model.attr("disabled","Y"); select_complect.attr("disabled","Y"); select_complect.html(""); var result = eval("("+data+")"); } catch (e){ return false; } if ($(picture).attr("class")!=undefined) { $(picture).hide(); $(picture).attr("src",result.PICTURE.SRC); $(picture).fadeIn(300); } if (result.COMPLECT!=undefined) { select_complect.removeAttr("disabled"); select_complect.html(result.COMPLECT); } select_model.removeAttr("disabled"); if (result.MODELS==undefined) select_model.attr("disabled","Y") else if (updateModel) { select_model.html(result.MODELS); }; }); }