<form-show-if> via unpkg

Import the guarded definition helper. See the README for the API.

Select Email to reveal the dependent field. Focus stays on the select. Without JavaScript or if the CDN import fails, the authored email field remains available. Check the console and import URL if enhancement fails; entered values remain in the native fields.

Automatic registration

<form>
  <label for="contact-method">Preferred contact method</label>
  <select id="contact-method" name="contact-method">
    <option value="">Select one</option>
    <option value="email">Email</option>
    <option value="phone">Phone</option>
  </select>
  <form-show-if conditions="contact-method=email">
    <label for="email">Email address</label>
    <input type="email" id="email" name="email" />
  </form-show-if>
</form>

<script type="module">
  import { defineFormShowIf } from
    'https://unpkg.com/@aarongustafson/form-show-if@latest/define.js?module';
  defineFormShowIf();
</script>