home *** CD-ROM | disk | FTP | other *** search
- <%
- '*******************************************************
- '* ASP 101 Sample Code - http://www.asp101.com *
- '* *
- '* This code is made available as a service to our *
- '* visitors and is provided strictly for the *
- '* purpose of illustration. *
- '* *
- '* Please direct all inquiries to webmaster@asp101.com *
- '*******************************************************
- %>
-
- <h2>Some sample radio button form elements:</h2>
-
- <form action="<%= Request.ServerVariables("URL") %>" method="get">
-
- A Default No-Frills Radio Button:
- <input type="radio" name="default" />
-
- <br />
-
- Radio Button With An Associated Value:
- <input type="radio" name="value_specified" value="Some Value" />
-
- <br />
-
- Multiple Radio Buttons With The Same Name:
- <input type="radio" name="multiple" value="1" />
- <input type="radio" name="multiple" value="2" />
- <input type="radio" name="multiple" value="3" />
-
- <br />
-
- Radio Button Which Maintains It's State:
- <input type="radio" name="state_keeper"
- <%
- ' This is the code that keeps the state of the radio
- ' button. All it does is check to see if the value
- ' returned is the same as the value parameter of the
- ' radio button input tag. If so, the radio button was
- ' enabled and we output the input tag's "checked"
- ' attribute to keep it that way.
- If Request.QueryString("state_keeper") = "on" Then
- Response.Write " checked=""checked"""
- End If
- %>
- />
-
- <br />
- <br />
-
- <input type="submit" />
-
- </form>
-
-
- <br />
- <br />
- <br />
-
-
- <h2>Let's check out our values just submitted:</h2>
- <blockquote><em>
- FYI: Note that the above form submits back to this same page.
- If you haven't yet submit the form then there won't be
- any values in the text below since they are retreived
- from the form. In this case, the values reflected are
- simply the defaults and are the same results you would
- get if you submitted the form without checking anything.
- </em></blockquote>
-
- <p><strong>The Default No-Frills Radio Button</strong></p>
- <p>
- By default, an HTML radio button element returns nothing
- if it wasn't enabled and a value of "on" if it
- was. So by checking it's value we can determine if it was
- enabled or not when the form was submitted.
- The No-Frills Radio Button was: <strong>
- <%
- ' Note that "on" is in lower case. Since writing "on"
- ' doesn't do much good, I simply check for it to determine
- ' which branch of the conditional to execute. I could
- ' place whatever code I wanted inside either condition.
- ' In this case I simply print out a "user-friendly" message.
- If Request.QueryString("default") = "on" Then
- Response.Write "Enabled"
- Else
- Response.Write "Disabled"
- End If
- %>
- </strong>.
- </p>
-
- <p><strong>Radio Button With An Associated Value</strong></p>
- <p>
- If you don't like the fact that the radio button returns the
- value of "on" it's really easy to change. Simply
- add a value parameter and assign to it what you'd like the
- value returned by the radio button to be.
- The Radio Button With An Associated Value returned:
- <strong><%= Request.QueryString("value_specified") %></strong>.
- </p>
-
-
- <p><strong>Multiple Radio Buttons With The Same Name</strong></p>
- <p>
- Similarly to the checkbox, the scenario where you have a set
- of radio buttons all with the same name is probably one of the
- most useful ways to use this type of input tag. The main
- difference is that instead of allowing a user to specify
- multiple answers to one question, the radio button element
- ensures that one and only one selection is choosen from among
- the group of buttons that share a common name.
- Multiple Radio Buttons With The Same Name ensured that only one
- choice was selected and it was:
- <strong><%= Request.QueryString("multiple") %></strong>.
- </p>
-
- <p><strong>Radio Button Which Maintains It's State</strong></p>
- <p>
- At this point there's really nothing different about
- this radio button from any other, but I thought I should
- illustrate the technique when building the form
- (see the form generating section of the source code)
- because it's so useful in real life. In particular, when
- you're sending a user back to the form to check their
- entries, it's really frustrating for them if they have
- to re-enter all their values and re-select all the appropriate
- radio buttons.
- </p>
- <p>
- In terms of the value, like I said, this is just like the
- standard radio button, but just to keep up the pattern...
- Radio Button Which Maintains It's State returned:
- <strong><%= Request.QueryString("state_keeper") %></strong>.
- </p>
-
-
- <%
- ' Here's a little function that you might find handy.
- ' It takes the name parameter of the radio button you want
- ' to check and will return a boolean indicating if a
- ' radio button with that name was enabled on the form when
- ' the user submitted it even if the value of the
- ' radio button isn't set to anything. It works well to
- ' help simplify your code... especially in conditionals.
- Function IsChecked(strFieldName)
- Dim blnChecked
-
- If Request.QueryString(strFieldName).Count > 0 Then
- blnChecked = True
- Else
- blnChecked = False
- End If
-
- IsChecked = blnChecked
- End Function
-
- ' For example, using the state_keeper example above:
- 'If IsChecked("state_keeper") Then
- ' ' The radio button was enabled.
- 'End If
- %>
-