Skip to content

JavaScript Tutorial Forms and Validation

Checkbox, Radio and Select Values in JavaScript

Lesson 127 of 258 2 min read By Deepak Paswan Updated Oct 4, 2026

Different controls store their state in different properties.

Checkboxes: checked

A checkbox is on or off. Read checked, not value.

index.html
HTML
<label><input type="checkbox" id="terms"> I accept the terms</label>
<script>
  const box = document.querySelector("#terms");

  console.log(box.checked); // → false
  box.checked = true;
  console.log(box.checked); // → true
  console.log(box.value);   // → on   (the value sent with a form, "on" by default)
</script>

Radio buttons: one choice from a group

Radios in a group share a name. Find the checked one.

index.html
HTML
<label><input type="radio" name="plan" value="free" checked> Free</label>
<label><input type="radio" name="plan" value="pro"> Pro</label>
<script>
  const chosen = document.querySelector("input[name='plan']:checked");
  console.log(chosen.value); // → free

  document.querySelectorAll("input[name='plan']").forEach(radio => {
    radio.addEventListener("change", () => console.log("Plan:", radio.value));
  });
</script>

The CSS selector :checked finds the selected one. If none is selected, the result is null, so check before using .value.

Select menus

index.html
HTML
<select id="city">
  <option value="">Choose…</option>
  <option value="pune">Pune</option>
  <option value="delhi" selected>Delhi</option>
</select>
<script>
  const select = document.querySelector("#city");

  console.log(select.value);                               // → delhi
  console.log(select.selectedIndex);                       // → 2
  console.log(select.selectedOptions[0].textContent);      // → Delhi
  select.value = "pune";                                   // choose by value
  console.log(select.value);                               // → pune
</script>

Multiple selection

index.html
HTML
<select id="tags" multiple>
  <option value="js" selected>JS</option>
  <option value="css">CSS</option>
  <option value="html" selected>HTML</option>
</select>
<script>
  const values = [...document.querySelector("#tags").selectedOptions].map(o => o.value);
  console.log(values); // → ["js", "html"]
</script>

A group of checkboxes

index.html
HTML
<label><input type="checkbox" name="topic" value="js" checked> JS</label>
<label><input type="checkbox" name="topic" value="css"> CSS</label>
<label><input type="checkbox" name="topic" value="html" checked> HTML</label>
<script>
  const checked = [...document.querySelectorAll("input[name='topic']:checked")].map(c => c.value);
  console.log(checked); // → ["js", "html"]
</script>

Quick reference

ControlReadEvent
Text, textareavalueinput
Checkboxcheckedchange
Radio groupquerySelector(":checked").valuechange
Selectvaluechange
Multiple selectselectedOptionschange
lightbulb
FormData does this for you
new FormData(form).getAll("topic") collects a group of checkboxes without a manual query. See FormData.