• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

RADIO BUTTON HELP!!!!!!

NO RADIO BUTTON SELECTED HELP!!!!!!

-I have three radio buttons.
-Right now a person must select a button.
-Once they have selected the button a value is sent to a database.
-I would like to set it up so that they don't have to select any of the radio buttons and a if they don't I send a value, different from the other 3 values, to the database

-HERE IS MY CONCERN/QUESTION:

-How do I set it up so that they don't have to choose any of the 3 buttons.
-How can I send a value to the database if they don't choose any of the 3 buttons?

Here is an example of what I need:

Please Select from the following:

[radio button] Choice A.
[radio button] Choice B.
[radio button] Choice C.

If none of these are buttons are clicked then send value X to the database.

If you have any other questions you can email me at king@cs.byu.edu/mtking@novell.com
0
mtking
Asked:
mtking
1 Solution
 
Le_RonCommented:
Add a script for the onLoad event of the form, where you declare a variable (let's call it 'res')initialized with X. Add an onClick event on each of the radio button where you set res to the radio value.

<html>
....
<body onLoad="res='X'">
<inupt name=rad1 type=radio name=grp value="A" onClick="res='A'">
<inupt name=rad2 type=radio name=grp value="A" onClick="res='B'">
<inupt name=rad3 type=radio name=grp value="A" onClick="res='C'">
....
</body>
</html>

Or something like that

Another thing you can do is to test the checked state of your buttons before sending the value to the DB. If none is checked, send the value you want.

Hope this helps
0
 
mawhinneyCommented:
You could also use a hidden field containing the default value.  If any of the radio buttons are selected, set the default value to nothing. On the next page, if that hidden field has a value, you know none of the radio buttons were selected.

<input type=radio name=rad1 value="A" onclick="document.myform.rad4.value=''">
<input type=radio name=rad2 value="B" onclick="document.myform.rad4.value=''">
<input type=radio name=rad3 value="C" onclick="document.myform.rad4.value=''">
<input type=hidden name=rad4 value="X">
0
 
chuckie79Commented:
or another alternative is to have four radio buttons, one of which is nothing

<FORM ...>
....
<INPUT TYPE=RADIO NAME="option_1" VALUE="none" CHECKED>None</INPUT><BR>
<INPUT TYPE=RADIO NAME="option_1" VALUE="a">Choice A</INPUT><BR>
<INPUT TYPE=RADIO NAME="option_1" VALUE="b">Choice B</INPUT><BR>
<INPUT TYPE=RADIO NAME="option_1" VALUE="c">Choice C</INPUT><BR>
....
</FORM>

Data is then processed by the second page, if no option is selected then register this in database.

hope this helps

chuckie
0
 
Rich6176Commented:
Try this script with this form it should be want your looking for. The value of hidden will be sent to the server unless a radio was selected and then the radio button value will be sent instead.


<SCRIPT language=javascript>
function checkForm()
{
 var value;
 var wasRadio=false;

      for(var i = 0; i < document.reg.length; i++)
      {
         if (document.reg.elements[i].checked == true)
         {
            value = document.reg.elements[i].value;
            wasRadio = true;
         }
      }
   if (!wasRadio)
      document.reg.hide.value = "Whatever value you want sent back";

   document.reg.submit();");
}
</SCRIPT>

<!-- And the form looks like this-->
<FORM name=reg method=something>
   <INPUT type=radio name=radio value=1>
   <INPUT type=radio name=radio value=2>
   <INPUT type=radio name=radio value=3>
   <INPUT type=hidden name=hide>
</FORM>
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now