Collecting checkbox values in Classic ASP

Checkboxes are useful when a visitor may select zero, one, or several options. When several checkboxes share the same name, Classic ASP can receive the selected values as one comma-separated request value.

Example form:

<form method="post" action="form-checkboxck.asp">
  <label><input type="checkbox" name="games" value="cricket"> Cricket</label>
  <label><input type="checkbox" name="games" value="football"> Football</label>
  <label><input type="checkbox" name="games" value="tennis"> Tennis</label>
  <label><input type="checkbox" name="games" value="hockey"> Hockey</label>
  <button type="submit">Submit</button>
</form>

Read the posted value explicitly from Request.Form:

Dim games, gameList, i
games = Request.Form("games")

If nothing is selected, the value may be empty. Check that before splitting it.

If Len(games) > 0 Then
  gameList = Split(games, ",")
End If

Then loop through the resulting VBScript array:

For i = LBound(gameList) To UBound(gameList)
  Response.Write Server.HTMLEncode(gameList(i)) & "<br>"
Next

For a fixed set of allowed values, validate each submitted item against that allow-list before using it in application logic or storing it.

A similar PHP example is available in the PHP checkbox-array tutorial.


ASP Home



Tom

22-10-2012

Using your "Getting the checked values of checkbox Array of a form in ASP" method, could you tell me how I would also get the unique ID of the checked checkbox in "form-checkboxck.asp"
Shashidhara

22-02-2013

Thank you.. Useful post..



✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer