Bullschmidt.com


     Home
     Web Database Concept
     How We Work Together
     Bio
     Web Database Sample
     Classic ASP Design Tips
     Bar Chart Tool
     Web Design Resources
     Access Database Sample

Classic ASP Design Tips
Checkboxes
These are opinions of J. Paul Schmidt, MBA.
No warranties are either expressed or implied.
To Use Paul's Services: Paul@Bullschmidt.com

First of all let's have a variable called IsPaid which could be set from a field in a database's recordset:

<%
IsPaid = objRS("IsPaid")
%>

Or from a posted form field:

<%
IsPaid = Request.Form("IsPaid")
%>

And within a form the checkbox input tag calls a custom function named jpsvbBoolToChecked() which basically just returns the word checked (which means that the checkbox would have a checkmark in it) if needed:

<input type="checkbox" name="IsPaid" <%= jpsvbBoolToChecked(IsPaid) %> value="Yes">

And here is the jpsvbBoolToChecked() function with several lines of comments toward the top which could reside on the same ASP page or be on an included page:

<%
Function jpsvbBoolToChecked(pvarFld)
  ' Convert True, "True", "true", "Yes", or "yes" to "checked", otherwise "".
  ' Used for dealing with HTML checkbox or radio button which has
  ' checked attribute if checked otherwise doesn't have it.
  ' Specifically use this in the input tag.
  ' Example (Checkbox): <input <%= jpsvbBoolToChecked(MyFld) %> blah... >
  ' Example (Radio Button): <input <%= jpsvbBoolToChecked(MyFld = "Red") %> blah... >

  If (pvarFld = True) Or (pvarFld = "True") Or (pvarFld = "true") Or (pvarFld = "Yes") Or (pvarFld = "yes") Then
    jpsvbBoolToChecked = "checked"
  Else
    jpsvbBoolToChecked = ""
  End If
End Function
%>

Thus the resulting HTML code which a user could see by doing right-click | View Source would either be this (and notice that the word checked is in here):

<input type="checkbox" name="IsPaid" checked value="Yes">

And would look like this:



Or the resulting HTML code would be this (and notice that the word checked is NOT in here):

<input type="checkbox" name="IsPaid" value="Yes">

And would look like this:







To Use Paul's Services:
Paul@Bullschmidt.com

Let's put some data on the Web!
Copyright © 2000-2014
J. Paul Schmidt, MBA
Freelance Web and Database Developer
All Rights Reserved

Privacy Policy