Book An Appointment

Book an appointment

Book an appointment with your trusted partner for orthodontic excellence. At MyBracesClinic, we craft beautiful smiles with expertise and care, aided by the latest technology.

For a faster response, please WhatsApp your preferred MBC branch:

<script>
document.addEventListener('DOMContentLoaded', function () {
  function getQueryParam(name) {
    return new URLSearchParams(window.location.search).get(name);
  }

  var selectedDoctor = getQueryParam('doctor');
  if (!selectedDoctor) return;

  function applySelection() {
    // Adjust this selector if the doctor field's input name is different.
    var selects = document.querySelectorAll('select[name="input_20"]');
    var applied = false;

    selects.forEach(function (select) {
      for (var i = 0; i < select.options.length; i++) {
        var optionValue = select.options[i].value;
        // Substring match, case-insensitive: works whether the value is
        // English ("Dr CHONG Hui Theng") or Chinese
        // ("张慧婷医生 (Dr. CHONG HuiTheng)") because the English name/
        // surname is present in both, untranslated.
        if (optionValue && optionValue.toUpperCase().indexOf(selectedDoctor.toUpperCase()) !== -1) {
          select.value = optionValue;
          // Let Gravity Forms / conditional logic know the value changed
          select.dispatchEvent(new Event('change', { bubbles: true }));
          applied = true;
          break;
        }
      }
    });

    return applied;
  }

  // Try right away; if the form loads slightly after DOMContentLoaded
  // (e.g. via AJAX), keep retrying briefly instead of giving up.
  if (!applySelection()) {
    var attempts = 0;
    var timer = setInterval(function () {
      attempts++;
      if (applySelection() || attempts > 20) {
        clearInterval(timer);
      }
    }, 250);
  }
});
</script>