BOOK A TEST DRIVE

  • Book a Test Drive

    I would like to hear about latest offers, special promotions and new product launches from MG Motor Australia

    I agree that my information will be handled by MG Motor Australia in accordance with their Privacy Policy.

document.addEventListener('DOMContentLoaded', function () { let allModels = []; // store data globally for both dropdowns async function fetchAndPopulateModelDropdown() { try { const response = await fetch('https://zohoapi.mgmotor.com.au/get_models_for_book_a_test_drive.php?file_name=all_models.json'); // const response = await fetch('https://demoaspire.com/curl_example1/get_models_for_book_a_test_drive.php?file_name=all_models.json'); if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`); const data = await response.json(); allModels = data.result.Model_List || []; const dropdown = document.getElementById('modelDropdown'); dropdown.innerHTML = ''; // Get product title from URL if exists const urlParams = new URLSearchParams(window.location.search); let productTitle = urlParams.get('product'); let selectedFound = false; const normalize = str => str?.toLowerCase().replace(/^mg\s+/i, '').trim(); allModels.forEach(model => { const decodedDescription = model.Model_Generation_Description.replace(/ /g, ' ').trim(); const option = document.createElement('option'); option.value = decodedDescription; option.textContent = decodedDescription; if (productTitle && !selectedFound) { const normProduct = normalize(productTitle); const normModel = normalize(decodedDescription); if (normProduct === normModel) { option.selected = true; selectedFound = true; } } dropdown.appendChild(option); }); // Trigger Powertrain dropdown if model was auto-selected if (selectedFound) { populatePowertrainDropdown(dropdown.value); } } catch (error) { console.error('Error fetching model list:', error.message); } } function populatePowertrainDropdown(selectedModel) { const powertrainDropdown = document.getElementById('modelDropdown_powertain'); powertrainDropdown.innerHTML = ''; if (!selectedModel) return; const normalize = str => str?.toLowerCase().replace(/^mg\s+/i, '').trim(); const modelMatch = allModels.find(model => normalize(model.Model_Generation_Description) === normalize(selectedModel) ); if (!modelMatch || !Array.isArray(modelMatch.Model_BATD_List)) return; const powertrains = modelMatch.Model_BATD_List; if (powertrains.length === 0) { powertrainDropdown.innerHTML += ''; } else { powertrains.forEach(pt => { const option = document.createElement('option'); option.value = pt; option.textContent = pt; powertrainDropdown.appendChild(option); }); // ✅ Auto-select if only one powertrain exists if (powertrains.length === 1) { powertrainDropdown.value = powertrains[0]; } } } // Attach change listener to modelDropdown document.getElementById('modelDropdown').addEventListener('change', function () { populatePowertrainDropdown(this.value); }); // Fetch and populate model dropdown fetchAndPopulateModelDropdown(); });

PRIVACY

Your contact details are being collected by MG Motor Australia to enable us to record the details of the vehicle you are interested in and to consider the purchase of your trade-in vehicle. We may disclose your personal information to third parties to check whether and how, your vehicle is encumbered. From time to time, MG Motor Australia would like to contact you and to let you know about our products and services, including special offers. If you do not want us to do so, please let us know by contacting us. You can let us know at any time if you no longer wish to be contacted for these purposes. Your consent will remain current until you advise us otherwise. If you do not provide us with your personal information, we may not be able to consider any offer made by you. If you would like to access the information we hold about you or more information on our privacy policy, please contact us at https://mgmotor.com.au/.