Source Code
<div class="container py-5 d-flex justify-content-center">
<div class="card bscond-card">
<div class="card-body p-4">
<label class="form-label small fw-semibold">How do you plan to use this?</label>
<select class="form-select mb-3" id="bscondType">
<option value="">Select one...</option>
<option value="personal">Personal</option>
<option value="business">Business</option>
<option value="nonprofit">Nonprofit</option>
</select>
<div class="bscond-group d-none" id="bscondBusinessFields">
<label class="form-label small fw-semibold">Company name</label>
<input type="text" class="form-control mb-2" id="bscondCompany">
<label class="form-label small fw-semibold">Tax ID</label>
<input type="text" class="form-control mb-3" id="bscondTaxId">
</div>
<div class="bscond-group d-none" id="bscondNonprofitFields">
<label class="form-label small fw-semibold">Organization name</label>
<input type="text" class="form-control mb-2" id="bscondOrgName">
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="bscondRegistered">
<label class="form-check-label small" for="bscondRegistered">We're a registered 501(c)(3)</label>
</div>
</div>
<div class="bscond-group d-none" id="bscondEinField">
<label class="form-label small fw-semibold">EIN</label>
<input type="text" class="form-control mb-3" id="bscondEin">
</div>
<button type="button" class="btn btn-dark btn-sm fw-bold w-100" id="bscondSubmit">Continue</button>
</div>
</div>
</div>.bscond-card { width: 360px; max-width: 100%; border: 1px solid #eceef1; border-radius: 14px; }const type = document.getElementById('bscondType');
const businessFields = document.getElementById('bscondBusinessFields');
const nonprofitFields = document.getElementById('bscondNonprofitFields');
const einField = document.getElementById('bscondEinField');
const registered = document.getElementById('bscondRegistered');
function update() {
const v = type.value;
businessFields.classList.toggle('d-none', v !== 'business');
nonprofitFields.classList.toggle('d-none', v !== 'nonprofit');
// A second-level condition: the EIN field only shows for a nonprofit that
// has also checked "registered 501(c)(3)" — nested conditional logic, not
// just a flat one-field-per-option mapping.
einField.classList.toggle('d-none', !(v === 'nonprofit' && registered.checked));
}
type.addEventListener('change', update);
registered.addEventListener('change', update);
update();Bootstrap Conditional Form Fields — Free HTML CSS JS Snippet
Bootstrap Conditional Form Fields · Forms · Plain HTML, CSS & JS · Live preview
What's included
Features
About this UI Snippet
Bootstrap Conditional Form Fields — HTML, CSS & JavaScript

A single update() function is the only place field visibility is decided, called from every input that could affect it — the type <select>'s change event and the "registered 501(c)(3)" checkbox's own change event both trigger the same function, rather than each control owning its own separate show/hide logic that could get out of sync with the others.
The business and nonprofit field groups are straightforward one-condition toggles (v !== 'business' hides the business group), but the EIN field demonstrates something a flat "one field shows per dropdown option" implementation can't: it only appears when v === 'nonprofit' && registered.checked are *both* true — selecting Nonprofit alone isn't enough, and checking "registered" while some other type is selected isn't enough either. That's a genuinely nested condition, not just a wider switch statement.
Running update() unconditionally on load (not just after a user interacts) means the form's visible fields always match its actual current state from the very first render — important for a form that might load pre-filled with existing data rather than starting from a blank selection every time.
Build with AI
Build, Understand, Optimize, and Extend It With AI
Hand this snippet to an AI coding assistant like Claude and ask it to preserve values typed into a field group when it's hidden and later re-shown (rather than the user needing to retype them), or to add form validation that only requires fields belonging to the currently visible groups, ignoring hidden ones entirely.
Prompt to recreate it
Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:
Build a Bootstrap 5.3 form with conditional field groups, using the real Bootstrap CDN framework (bootstrap.min.css and bootstrap.bundle.min.js), not custom CSS made to resemble it.
Requirements:
- A dropdown selecting an account type (e.g. Personal, Business, Nonprofit) that shows a different group of additional fields depending on the selection, hiding every other group.
- One additional field must depend on two separate conditions being true simultaneously — e.g. only appearing when a specific type is selected AND a related checkbox elsewhere in the form is also checked, not from the dropdown selection alone.
- Drive all field visibility from a single shared update function triggered by every relevant control's change event, not separate show/hide logic scattered per control.
- Ensure field visibility is correct immediately on page load, not only after the first user interaction, and that switching away from a selection correctly hides fields that were previously shown.Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.
Step by step
How to Use
- 1Load the snippetOnly the type dropdown shows; no additional fields are visible yet.
- 2Select "Business"Company name and Tax ID fields appear immediately.
- 3Switch to "Nonprofit"The business fields disappear and organization name plus a registered-status checkbox appear instead.
- 4Check "We're a registered 501(c)(3)"An EIN field appears — it only shows because both the type is Nonprofit and this box is checked.
- 5Uncheck the box, or switch back to "Personal"The EIN field (and every conditional group) disappears again immediately.
Real-world uses
Common Use Cases
Got questions?
Frequently Asked Questions
An EIN is only relevant to a registered nonprofit specifically, not every nonprofit selection generally — modeling it as a single field tied only to the dropdown would either show it prematurely (before registration status is known) or require duplicating the field inside both branches.
Both the nonprofit fields and the EIN field hide immediately, since einField's visibility explicitly requires the type to be nonprofit — the checkbox being checked alone is never sufficient on its own.
Yes. Keep the type and registered values in component state, and compute each group's visibility as a derived boolean expression in the render function — no direct classList manipulation needed, since the framework handles conditional rendering natively.
Add another boolean condition to whichever field's visibility should depend on it, following the same pattern the EIN field already uses — update() has no fixed depth limit built into its structure.