Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Microsoft: ASP (Active Server Pages) FAQ

Form Handling

Reference form values in your ASP Scripts by onpnt
Posted: 20 Aug 03 (Edited 21 Aug 03)

Form referencing in your ASP scripts is often a hard process but is relatively trivial when you get the basics of how the objects are sent.  Below is going to be a set of four form objects and will be submitted via the URL or QueryString.  I do want to point out that there is a FAQ that references the Checkbox and Select a bit more.  It is
"How to get the results from a group of checkboxes or a select multiple"

So let's get started with the script you can run on your own to play with.  Just follow the comments.  This is going to be brief.  The idea of me writing the FAQ in this fashion was for you to run the below script and play with it to see how it works.

' below we just check to see if the form was submitted
If Request.QueryString("subButton") <> "" Then

' this declaration is for the select field.  Follow through to see why we need this
Dim selSplitArray

' first the checkbox
'as in the HTML form, the checkbox is either on or "" (empty)  it's that simple
If Request.QueryString("chk") = "on" Then
    Response.Write "Checkbox was checked | The value was "
    Response.Write "<span style=""color:red""> " & Request.QueryString("chk") & "</span><br>"
    Response.Write "Checkbox was not checked with no value attribute | There is no value to show!" & "<br>"
End If

' For the second checkbox with a value attribute
' we still need to validate a value passed
' never just do a Request.QueryString("chk2")
' or you will get a empty space in the page
' there are other methods but this is sound
If Request.QueryString("chk") <> "" Then
    Response.Write "<span style=""color:red""> " & Request.QueryString("chk2") & "</span><br>"
    Response.Write "Checkbox was not checked with value attribute | There is no value passed!" & "<br>"
End If

' for the select.  Remember the variable?  We need to create a array out of that
'selects are sent comma delimited so you need to split on that delimiter
'to get the values alone for processing.  I will not go into the function use here (split etc.)
If InStr(Request.QueryString("sel"),",") > 0 Then
    ' need to split them
    selSplitArray = Split(Request.QueryString("sel"),",")
    Response.Write "Values selected in the select box where <br>"
      Do While x <= Ubound(selSplitArray)
         Response.Write "Value "
         Response.Write "<span style=""color:red""> " & selSplitArray(x) & "</span><br>"
       x = x + 1
    Response.Write "No values passed in the select box!" & "<br>"
End If

' texts are the easiest.  Just call it driectly by name reference
If Request.QueryString("txt") <> "" Then
    Response.Write "The text input passed the following "
    Response.Write "<span style=""color:red""> " & Request.QueryString("txt") & "</span><br>"
    Response.Write "Nothing was passed by the text input<br>"
End If

'radio are identical to the checkbox's on or "" (empty)
If Request.QueryString("rad") = "on" Then
    Response.Write "Lastely the radio passed something | The value was "
    Response.Write "<span style=""color:red""> " & Request.QueryString("rad") & "</span><br>"
    Response.Write "radio was not selected | There is no value to show!" & "<br>"
End If

How form objects are passed and referenced in your ASP scripts.<br>

<form method="get">
Checkbox's are sent either ="" or ="on"<br>

<input type="checkbox" name="chk"><br>

CheckBox Part Two!<br>
Checkbox's sent with value attributes<br>

<input type="checkbox" name="chk2" value="my value"><br>

Select <br>
Multiple selected values are sent comma delimited.<br>
eg: one,three,five<br>

<select multiple name="sel">
<option value="one">one
<option value="two">two
<option value="three">three
<option value="four">four
<option value="five">five

Text input's are sent as is.<br>
eg: txt="" or txt="value"<br>

<input type="text" name="txt"><br>

Radios are the same as checkbox's<br>
<input type="radio" name="rad"><br>
<input type="submit" value="test to see them" name="subButton">
<% End If %>

See it working (demo) at

I'd like to thank jemminger for contributing on this FAQ.
In the checkbox discussion you will see two techniques.  value attribute and no value attribute.
Thanks jemminger for the great tip.   

Back to Microsoft: ASP (Active Server Pages) FAQ Index
Back to Microsoft: ASP (Active Server Pages) Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close