Показать сообщение отдельно
  #3 (permalink)  
Старый 02.05.2012, 02:15
Аватар для archcoffe
Интересующийся
Отправить личное сообщение для archcoffe Посмотреть профиль Найти все сообщения от archcoffe
 
Регистрация: 10.04.2012
Сообщений: 19

волею судьбы недавно тоже этим вопросом занимался по мануалу


$('#country_id').change(function () {
			        var country_id = $(this).val();
			        if (country_id == '0'  ) {
			            $('#region_id').html('');
			            $('#region_id').attr('disabled', true);
			            return(false);
			        }
			    
			        if ( country_id == 'NULL' || $('#city_id').val() >'0') {
			        	$('#city_id').html('');
				        $('#city_id').attr('disabled', true).html('<option>нет городов</option>');
			        }
			        
			        
			        $('#region_id').attr('disabled', true);
			        $('#label_region').hide();
			        $('#region_id').html('<option  value="0" >нет регионов</option>');
			        var url = '<?=base_url()?>arka/view/country/'+country_id;
			        $.post(
			            url,
			            function (result) {
			                if (result.type == 'error') {
			                    alert('error');
			                    return(false);
			                }
			                else {
			                    var options = '';
			                    $(result.regions).each(function() {
			                        options += '<option value="' + $(this).attr('id') + '">' + $(this).attr('title') + '</option>';
			                    });
			                    $('#region_id').html(options);
			                    $("#region_id").attr('disabled', false);
			                }
			            },
			            "json"
			        );
			    });
			    $('#region_id').change(function () {
			   		var region_id = $(this).val();
			   	    
			   		
			   		if (region_id == '0' ) {
			            $('#city_id').html('');
			            $('#city_id').attr('disabled', true);
			            return(false);
			        }
			   	 	
			        var url = '<?=base_url()?>arka/view/region/'+region_id;
			        $.post(
				            url,
				            function (result) {
				                if (result.type == 'error') {
				                    alert('error');
				                    return(false);
				                }
				                else {
				                    var options = '';
				                    $(result.city).each(function() {
				                        options += '<option value="' + $(this).attr('id') + '">' + $(this).attr('title') + '</option>';
				                    });
				                    $('#city_id').html(options);
				                    $("#city_id").attr('disabled', false);
				                }
				            },
				            "json"
				        );
			    });

Это у меня работает на тестовом.. После того как я это сделал, принялся делать другие подобные запросы.. И вы знаете что после этого думаю? - подход с двумя change функциями как то не очень().. Хочется сделать все в одну change функцию, - может я и не прав, но подумалось так..

Последний раз редактировалось archcoffe, 02.05.2012 в 02:32.
Ответить с цитированием