Form works on desktop, but improperly on mobile.
-
Hello guys. I have been stuck on this over 2 weeks.
If you go to my site at https://abautoglass.net/contact-us/
there is a form. On PC, I can select year, make, model, and trim just fine. IF I try this on mobile device, I select year, then make. BUT when it comes to selecting model, it starts to show models for ALL cars and not the one I specified….
Please please please help if you can :'(
Here is the javascript that goes with it in the footer.
PS: I think its because it gets make and model at the same time.<script> var protoCall = "https://"; var host = "api.edmunds.com"; // Make sure to change the API KEY var apiKey = "kdrpch68q5kmjrb42nmne562"; var fmt = "json"; var standardParams = "&fmt=" + fmt + "&api_key=" + apiKey + "&callback=?"; var $yearSelect = jQuery('#ajYears'); var $makeSelect = jQuery('#ajMakes'); var $modelSelect = jQuery('#ajModels'); var $styleSelect = jQuery('#ajStyles'); // lets bind some events on document.ready. jQuery(function(){ $yearSelect.on('change', function() { getMakeModelsByYear()}); $makeSelect.on('change', function() { enableModelDropdown() }); $modelSelect.on('change', function() { getStyles() }); // lets build the year drop down. ajEdmundsBuildYear(); }); // method to build the year drop down. function ajEdmundsBuildYear() { var baseYear = 1990, endYear = new Date().getFullYear(); $yearSelect.empty(); $yearSelect.append('<option value="-1">Select Year</option>'); for(var yyyy=baseYear; yyyy<=endYear; yyyy++) { $yearSelect.append('<option value="' + yyyy + '">' + yyyy +'</option>'); } } // get the makes and models for a year in one go... function getMakeModelsByYear() { var year = $yearSelect.val(), endPoint = "/api/vehicle/v2/makes", view = "basic", options = "year=" + year + "&view=" + view + standardParams, postURL = protoCall + host + endPoint + "?" + options; jQuery.getJSON(postURL, function(data) { // clear the make drop down... re add the first option... remove dsiabled attr. $makeSelect.empty(); $makeSelect.append('<option value="-1">Select Make</option>'); $makeSelect.removeAttr('disabled'); $modelSelect.empty(); $modelSelect.append('<option value="-1">Select Model</option>'); // loop the makes... each make contains model... add the make in make drop down and models in model dd jQuery.each(data.makes, function(i, val) { make = data.makes[i]; $makeSelect.append('<option value="' + make.niceName + '">' + make.name + '</option>'); jQuery.each(make.models, function(x, val){ model = make.models[x]; $modelSelect.append('<option make="' + make.niceName +'" value="' + model.niceName + '">' + model.name + '</option>'); }); }); }); } // since we already grabed the models... // now just matter of showing only the matching models for a make. function enableModelDropdown() { var make = $makeSelect.val(); $modelSelect.removeAttr('disabled'); $modelSelect.find('option').not('[value="-1"]').hide(); $modelSelect.find('option[make=' + make + ']').show(); } // grab the styles... pretty much same as // getMakeModelsByYear() function getStyles() { var year = $yearSelect.val(), make = $makeSelect.val(), model = $modelSelect.val(), endPoint = "/api/vehicle/v2/" + make + "/" + model + "/" + year + "/styles", view = "basic", options = "view=" + view + standardParams, postURL = protoCall + host + endPoint + "?" + options; jQuery.getJSON(postURL, function(data) { $styleSelect.empty(); $styleSelect.removeAttr('disabled'); $styleSelect.append('<option value="-1">Select Style</option>'); jQuery.each(data.styles, function(i, val) { style = data.styles[i]; $styleSelect.append("<option value='" + style.id + "'>" + style.name + "</option>"); }); }); } </script>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Form works on desktop, but improperly on mobile.’ is closed to new replies.