p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

asp_databases thread: Radio buttons


Message #1 by "WVerner" <w_verner@h...> on Tue, 18 Mar 2003 23:48:38
hi guys,
i have another problem probably easily solved but 
your replies do help me learn! so thanks.

What i want to do is essentially update a table. 
However i want to incorporate a radio button. When the
user clicks submit, it sees if the radio button is checked 
and if so, updates a Boolen value in the table to True.

At moment i have a form with text fields in it, but rather
than have the user change the value of a text field from False
to True to change it, i want some way of them just clicking a 
button to do it..Im sure its possible?

thanks in advance,
Message #2 by skip@f... on Fri, 21 Mar 2003 04:49:19
Perhaps what you really need is a checkbox. Radio buttons are used when 
multiple selections apply, of which only one per radio button group may be 
selected.

For the checkbox:
  <INPUT name="whatchamacallit" type="checkbox" value="1">Pick me!

For multiple choice (only one can be selected):
  <INPUT name="whatchamacallit" type="radio" value="0">Pick me!
  <INPUT name="whatchamacallit" type="radio" value="1" checked>No, pick me!

However, with both of these elements, if the user doesn't check the box 
(checkbox) or you don't set a default "checked" radio element and the user 
picks nothing, then nothing gets posted. To further complicate things, 
initializing the elements from existing data can be a pain.

Best bet:

  <SELECT name="whatchamacallit">
  <OPTION value="0">No
  <OPTION value="1" selected>Yes
  </SELECT>

Now you can be sure that the user will send you something (the "value" is 
sent). In the example above, adding "selected" to an OPTION makes it the 
default value. Plus, variations of the SELECT element allow multiple 
selections. And, if you're still not sold, initializing is a piece of 
cake: simply set the element's value, just as you would an INPUT element - 
in client-side script, of course.

Skip

  Return to Index