/* $(function() { $('#country').on('change', function(){ var theForm = $(this).closest('form'); var selected = $(this).find("option:selected").val(); if (selected=='ESP'){ theForm.find('#location-content').removeClass('hide'); theForm.find('input#location').prop('disabled', false).focus(); } else{ theForm.find('input#location').val("").prop('disabled', 'disabled'); theForm.find('#location-content').addClass('hide'); } }); }); */ // --- get provinces with ajax and cache var cache = {}; function getProvinces(countryId, callback) { // load provinces with ajax or from cache if(!cache[countryId]) { cache[countryId] = $.getJSON("?fn=getProvinces", 'selected='+countryId, "json").promise(); } cache[countryId].done(callback); } // --- load provinces in select object, callback function function loadProvinces(datos){ if (datos['error']){ //show error message alert(datos['error']); } else{ //load provinces in select var provinces = datos['provinces']; $('#province').empty(); for (var i=0; i' + provinces[i].title + ''); } $('#province').prop('disabled', false); $('#province').prop('selectedIndex',0); $('#province').focus(); } } $(function() { $('#country').on('change', function(){ var selected = $(this).find("option:selected").val(); if (selected=='ESP' || selected=='PRT'){ $('#province-content').removeClass('hide'); // load provinces with ajax getProvinces(selected, loadProvinces); } else{ $('#province').prop('disabled', 'disabled'); $('#province').prop('selectedIndex',0); $('#province').empty(); $('#province-content').addClass('hide'); } }); });