473,320 Members | 2,122 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,320 software developers and data experts.

Empty Field (Radio button) validation

I am using a set of radio buttons in my asp.net (using C#) application. On click of the submit button i need to confirm whether the radio buttons have been checked using javascript. i am trying to take the value using the following line of code.

if (document.getElementById("rbtnlist_Q1").value == "")
{
alert("Please choose an option for Question no:1");
}


but the value remains undefined. How do i validate for unchecked radio buttons???
Mar 7 '07 #1
3 8710
vee10
141 100+
hi,

The below code may solve ur problem

if(document.getElementById("rbtnlist_Q1").checked= =false)
alert("Please choose an option for Question no:1");


I am using a set of radio buttons in my asp.net (using C#) application. On click of the submit button i need to confirm whether the radio buttons have been checked using javascript. i am trying to take the value using the following line of code.

if (document.getElementById("rbtnlist_Q1").value == "")
{
alert("Please choose an option for Question no:1");
}


but the value remains undefined. How do i validate for unchecked radio buttons???
Mar 7 '07 #2
acoder
16,027 Expert Mod 8TB
To validate for radio buttons, you have to go through the array of radio buttons and check each one separately to see if it has been checked. See this link. That should solve your problem.
Mar 7 '07 #3
gauravgmbhr
107 100+
To validate for radio buttons, you have to go through the array of radio buttons and check each one separately to see if it has been checked. See this link. That should solve your problem.


TRY the following code


m suppossing that ur form name is ="form"


Expand|Select|Wrap|Line Numbers
  1. function alert_empty_radio()
  2. {
  3. for(i=0;i<document.form.radios.length;i++)       
  4.  
  5. if(document.form.radios[i].checked==false)
  6. {
  7. flag=1;
  8. }
  9. else {
  10. flag=0;
  11. break;
  12. }
  13. }  //end loop
  14.  
  15.  
  16.  
  17. if(flag==1)
  18. {
  19. alert('ur custom message');
  20. }
  21. }//end function
  22.  
Mar 7 '07 #4

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

Similar topics

4
by: mitch-co2 | last post by:
What I am trying to do is when someone clicks on the YES radio button I want the text field called MYTEXT to equal the text field named DATE. The below code works as long as I do NOT UN-COMMENT...
5
by: Thejo | last post by:
Hi all, I started programming in PHP recently and have a query about empty $_POST arrays. I can see two scenarios when this could happen. 1. When some tries to directly load the page to which...
6
by: Blinky | last post by:
Hi all, I have a dynamically generated page that can have 1 or more radio buttons. I am using javascript with onsubmit in the form statement to make sure a radio button is selected before...
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...
1
by: FunkHouse9 | last post by:
I'm trying to develop an order page and in one section, the customer specifies a shipment type using radio buttons that is submitted to the shopping cart. There are 4 buttons. If either of the...
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.