Solved

RADIO BUTTON HELP!!!!!!

Posted on 2000-04-27
4
225 Views
Last Modified: 2010-04-09
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
Comment
Question by:mtking
4 Comments
 

Expert Comment

by:Le_Ron
ID: 2755688
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
 

Expert Comment

by:mawhinney
ID: 2761383
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
 
LVL 2

Expert Comment

by:chuckie79
ID: 2764039
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
 

Accepted Solution

by:
Rich6176 earned 100 total points
ID: 2777282
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Library to convert HTML to PDF. 8 55
AngularJS Page Control Understanding 5 38
Form not operating correctly. 1 22
Put shading on half of picture 8 21
This article discusses four methods for overlaying images in a container on a web page
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now