function CPCSimpleFormCustomJS() { this.innrykkrabatt = function() { } this.calculate = function(idstr) { console.log("this.calculate", idstr); } // * Called on all value changes in the form. this.change = function(el) { console.log("this.change", el); } // * On AjaxLoaded. this.ajaxloaded = function(el) { console.log("this.ajaxloaded", el); } // * Called on all value changes in the form. this.change = function(el) { console.log("this.change", el, $(this)); if ($(el).hasClass('zipcode')!==-1) { $.getJSON( "/cpclass/run/kommune/postnummer.php", {val: $(this).val(), 'op': 'lookupzip,schools', schoolclass: 'grunnskole' }, function( data ) { /* city: "OSLO" county: "Oslo" countyid: "0301" opwas: "lookupzip" region: "Oslo" regionid: "03" status: "OK" zipcode: "0551" */ $('input.sfx-sted, input.sfx-city').val(data.city).prop('readonly', true); $('input.sfx-fylke, input.sfx-region').val(data.region).prop('readonly', true); $('input.sfx-kommune, input.sfx-count').val(data.county).prop('readonly', true); $('input.sfx-kommune, select.sfx-fylke').parents('div.cpselementcontainer').hide(); var ke = $('input.sfx-skole, select.sfx-skole'); var keid = $(ke).attr('id') var name = $(ke).attr('name'); $("input.sfx-skole, select.sfx-skole").replaceWith(''); if (data.schools.error) { $('#'+keid).append(''); } else { $(data.schools).each(function(i,e) { $('#'+keid).append(''); }); } // Select fylke for selectbox $('select.sfx-fylke').each(function(i, el) { var findx = " - "+data.regionid; $(el).find('option').each(function(j, je) { if ($(je).text().indexOf(findx)>-1) $(el).val( $(je).val() ); }); }); }); } } // * Called on form submit. this.submit = function(el) { console.log("this.submit", el); } } var sfCustomJS = new CPCSimpleFormCustomJS();