473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

radio list validation

how to validate a radiolist for being left unchecked, using javascript
Nov 11 '05 #1
2 4013
Niheel
2,460 Expert Mod 2GB
Here is sample code on radio list validation:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <script language = "Javascript">
  3. var form='form1'
  4. function ValidateRadio()
  5. {
  6. var radio_choice = false;
  7.  for (counter = 0; counter < radio_form.radio_button.length; counter++)
  8.  {
  9.   if (radio_form.radio_button[counter].checked)
  10.    radio_choice = true; 
  11.  }
  12.  if (!radio_choice){
  13.   alert("Please select Yes, No or Maybe.")
  14.   return (false);
  15.  }
  16.  return (true);
  17. }
  18. // -->
  19. </script> 
  20.  
  21. <form name="radio_form" method="get" action="#" onSubmit="return ValidateRadio()">
  22.  <input name="radio_button" type="radio" value="yes" />Yes
  23.  <input name="radio_button" type="radio" value="no" />No
  24.  <input name="radio_button" type="radio" value="no" />Maybe
  25. <input type='submit' name='' value='Submit'>
  26. </form>
  27.  
Nov 21 '05 #2
acoder
16,027 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
should be
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
The language attribute is deprecated.

The code posted uses the form name globally. It should be accessed via document or document.forms or by using an id and document.getElementById(), e.g.
Expand|Select|Wrap|Line Numbers
  1. var radio_form = document.radio_form;
  2. // alternatively
  3. //radio_form = document.forms["radio_form"];
  4. // another alternative:
  5. // radio_form = document.getElementById("radio_form");
  6. // which would require the form to have an id:
  7. <form name="radio_form" id="radio_form" ...>
Jun 12 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Matt | last post by:
The following code is try to validate if the user selects a radio button choice. I dont understand why document.UserInputs.question.value; gets undefined value even user make a choice. I tried...
13
by: tywillia | last post by:
Scenario: There are four questions, each with radio buttons to mark the choice "yes" or "no". I need only one yes per FORM (so if 2 is marked yes, there is no need for any others to be, etc) so...
4
by: TS | last post by:
My objective: To create a survey that asks people to rate a list of things in order of importance. I wish to prevent them from just rating every item in the list the same value. For example the...
8
by: David Cameron | last post by:
I noticed that using an HTMLInputRadioButton and specifying a value to be an empty string (""), this is overridden by ASP.Net which set the value of the control to be the same as the ID of the...
9
by: wreed | last post by:
I have a for loop seen below.... var the_form = document.getElementById(formName); for(var i=0; i<the_form.length; i++) { var temp = the_form.elements.type; if (temp == "radio") { for (x =...
5
by: swatidesai0407 | last post by:
hi im validating radio buttons i create dis radio button in php based on some how many records of my query. i wrote a javascript to validate this buttons. wat i do is dat wen no radio button...
0
by: Gary W. Smith | last post by:
Hello, I have a simple form with a radio button group on it and I need to do some basic validation based upon which button is checked. Here is a little more detail. if button one is...
8
by: photoboy | last post by:
I have racked by brain long enough on this, so now I need the help of someone who knows what they are doing. Here is what I am trying to achieve: First, I have two radio buttons (both unchecked)...
4
by: pureadrenaline | last post by:
Hey Guys, Please could anyone help me out with the following form I need to create a validation on the email field only if the user checked the radio button named Email. Thanks in advance. ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.