473,386 Members | 1,821 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,386 software developers and data experts.

input validation for radio button

2
hello everyone...i need some help here:

i have 50 radio buttons in my form, named s0,s1,s2,s3....s50...now i want to validate whether user clicks the 50 radio buttons. i want to make sure that they answer the 50 questions...i tried doing loops...but it was not working...anybody have any idea?please share with me...tnx in advance..
Sep 26 '07 #1
3 1589
gits
5,390 Expert Mod 4TB
hi ...

welcome to TSDN ...

please post the code you have tried so far ... so that we may have a closer look on it ...

kind regards
Sep 26 '07 #2
camme
2
Expand|Select|Wrap|Line Numbers
  1. function formCheck() {
  2. var radioSelected = false;
  3.  
  4. for(var i=0;i<50;i++)
  5. {
  6. var a ="s"+i;
  7. if((document.events.a[0].checked == false) & (document.events.a[1].checked==false) & (document.events.a[2].checked==false) & (document.events.a[3].checked==false))
  8. {
  9. radioSelected=false;
  10. break;
  11. }
  12. if (!radio_choice)
  13. {
  14. alert("Please select a letter.")
  15. return (false);
  16. }
  17. return (true);
  18. }
  19. }


the name of the radio buttons are s0,s1,s2,s3....s50
so i tried to loop but it did not recognize the radio button's name...
hopefully i will get the solution...
regards.
Sep 27 '07 #3
gits
5,390 Expert Mod 4TB
hi ...

some things to mention regarding your code ... i'll comment it in the code:

Expand|Select|Wrap|Line Numbers
  1. function formCheck() {
  2. var radioSelected = false;
  3.  
  4. for (var i = 0; i < 50; i++) {
  5.     var a = "s" + i;
  6.  
  7.     // the logical AND operator is && so your condition is wrong
  8.     if((document.events.a[0].checked == false) & (document.events.a[1].checked==false) & (document.events.a[2].checked==false) & (document.events.a[3].checked==false)) {
  9.         radioSelected = false;
  10.         break;
  11.     }
  12.  
  13.     // where did you define radio_choice?
  14.     // in case you want to have that message displayed
  15.     // when radioSelected is false that code is never executed
  16.     // because of the break above 
  17.     if (!radio_choice) {
  18.         alert("Please select a letter.")
  19.         return (false);
  20.     }
  21.  
  22.     return (true);
  23. }
  24. }
try to fix your code ... in case you need further help or some hints ... post back anytime

kind regards
Sep 27 '07 #4

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

Similar topics

0
by: Shane | last post by:
I've got a C# ASP.NET web form that fails to validate under certain conditions. I have a radio button that causes an AutoPostback that enables certain other elements on the form. If I click that...
2
by: Shane | last post by:
I've got a C# ASP.NET web form that fails to validate under certain conditions. I have a radio button that causes an AutoPostback that enables certain other elements on the form. If I click that...
7
by: Steve Wylie | last post by:
At work we use SNAP survey software. The software is capable of outputting a survey as a web page, in HTML, which we can tart up with Javascript for basic form validation if required. When the...
12
by: Randell D. | last post by:
Folks, I have a form called "ourTestForm". Its a test form - nothing special - it contains five input tags - they are named one, two, three, four and five. The input tags are of type...
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...
3
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table...
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...
2
by: poreko | last post by:
I am trying to validate the inputs of a form using javascript. The validation is working but the form is not been submitted after the inputs have been checked. I have been unable to find any error....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...

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.