?
Solved

RADIO BUTTON HELP!!!!!!

Posted on 2000-04-27
4
Medium Priority
?
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

770 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