Solved

RADIO BUTTON HELP!!!!!!

Posted on 2000-04-27
4
228 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

820 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