<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
$APPLICATION->SetTitle("");
?>
<?
include_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/iblock/include.php");
include_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/include/public_tools.php");
?>
<style type="text/css">
.border {
float: left;
margin: 10px 0 0 5px;
}
label {
padding-left: 5px;
}
select {
width: 130px;
font-family: Georgia, Times, "Times New Roman", serif;
font-size: 9pt;
color: #000;
}
</style>
<? $APPLICATION->AddHeadScript('../js/jquery-1.3.1.js')?>
<script type="text/javascript">
(function($){
// очищаем select
$.fn.clearSelect = function() {
return this.each(function(){
if(this.tagName=='SELECT') {
this.options.length = 0;
$(this).attr('disabled','disabled');
}
});
}
// заполняем select
$.fn.fillSelect = function(dataArray) {
return this.clearSelect().each(function(){
if(this.tagName=='SELECT') {
var currentSelect = this;
$.each(dataArray,function(index,data){
var option = new Option(data.text,data.value);
if($.support.cssFloat) {
currentSelect.add(option,null);
} else {
currentSelect.add(option);
}
});
}
});
}
})(jQuery);
</script>
<script type="text/javascript">
$(document).ready(function(){
// выбор модели
function adjustModel(){
var autoValue = $('#auto').val();
/* alert('Выбор модели' + autoValue); */
var tmpSelect = $('#model');
if(autoValue.length == 0) {
tmpSelect.attr('disabled','disabled');
tmpSelect.clearSelect();
} else {
$.getJSON('car.php',{auto:autoValue},function(data) { tmpSelect.fillSelect(data).attr('disabled',''); alert('ajax!');
});
}
};
$('#auto').change(adjustModel);
$('#model').change(function(){
if($(this).val().length != 0) { alert('Выбор сделан!'); }
});
});
</script>
<?
$rsElements1 = GetIBlockSectionList(14, 0, Array("sort"=>"asc"), 100);
?>
<div class="border">
<label>Марка</label><br />
<select id="auto" name="auto" >
<option value="">Выбрать марку</option>
<? foreach ($rsElements1->arResult as $element) {?>
<option value="<?= $element["ID"] ?>"><?= $element["NAME"] ?></option>
<?}?>
</select>
</div>
<div class="border">
<label>Модель</label><br />
<select id="model" name="model" disabled="disabled"></select>
</select>
</div>
<? require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?> |