Solved

RADIO BUTTON HELP!!!!!!

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

758 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

20 Experts available now in Live!

Get 1:1 Help Now