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

2 radio buttons validate

i want to dont let the user submit the form unless they answer these two radio buttons questions but i dont why isnot working the code
Expand|Select|Wrap|Line Numbers
  1. unction checkForm(obj) //This fuction shows that the user need to answer Question one
  2. {
  3. var el = document.forms[0].elements;
  4. for(var i = 0 ; i < el.length ; ++i) {
  5. if(el[i].name == "att") {
  6. var radiogroup = el[el[i].name];
  7. var itemchecked = false;
  8. for(var j = 0 ; j < radiogroup.length ; ++j) {
  9. if(radiogroup[j].checked) {
  10. itemchecked = true;
  11. break;
  12. }
  13. }
  14. if(!itemchecked) {
  15. alert("Please Answer Question One");
  16. if(el[i].focus)
  17. el[i].focus();
  18. return false;
  19. }
  20. }
  21. }
  22. return false;
  23. }
  24. //-->
  25. <!--
  26. function Checkanswers(obj) {
  27. var Invalid;
  28. Invalid= checkForm(obj.att);
  29. if (Invalid)
  30.       return (!Invalid);
  31.  
  32. //-->
  33. </script>
  34.  
  35. </head>
  36. <body>
  37. <form id="forms" method="post" action="http://tl28serv.uws.edu.au/twainfo/form.asp" onsubmit="return Checkanswers(this);"  >
  38. <h1> Advanced Standing Application </h1>
  39. <h3>1- Personal Details </h3>
  40. <h4> The questions with * are mandatory so please answer them-Thank you</h4>
  41. <p> Are you currently enrolled at UWS?*<br/>
  42. <input type="radio" name="att" value="n"/> No <br/>
  43. <input type="radio" name="att" value="y"/> Yes then  Student ID 
  44. <input type="text" name="ID" size="30" maxlength="8" onblur="checkNum(this)" />  </p>
  45. <p> Are you an international student?* <br/>
  46.  <input type="radio" name="int" value="N"/> No <br/>
  47.  <input type="radio" name="int" value="Y"/> Yes </p>
Apr 10 '09 #1
6 2281
acoder
16,027 Expert Mod 8TB
I would suggest you create a function for validating radio buttons and then call that for each radio button group, e.g.
Expand|Select|Wrap|Line Numbers
  1. function radiosChecked(radios) {
  2.     for(var i = 0; i < radios.length; i++) {
  3.         if(radios[i].checked)
  4.             return true;
  5.     }
  6.     return false;
  7. }
and called:
Expand|Select|Wrap|Line Numbers
  1. if (!radiosChecked(frm.att)) {
  2.     alert('error...');
  3.     return false;
  4. }
Apr 10 '09 #2
i did as you said bur is not working why?!--
Expand|Select|Wrap|Line Numbers
  1. //This fuction shows that the user need to answer Question one and three
  2. function radiosChecked(obj) {
  3.     for(var i = 0; i < radio.length; i++) {
  4.         if(radio[i].checked)
  5.             return true;
  6.     }
  7.     return false;
  8. }
  9.  
  10. }
  11. //-->
  12. <!--
  13. function Checkanswers(obj) {
  14. if (!radiosChecked(obj.att)) {
  15.     alert('Pease answer question one');
  16.     return false;
  17.  
  18. }
  19. }
  20. //-->
  21. </script>
  22.  
  23. </head>
  24. <body>
  25. <form id="forms" method="post" action="http://tl28serv.uws.edu.au/twainfo/form.asp" onsubmit="return Checkanswers(this);"  >
Apr 10 '09 #3
Dormilich
8,658 Expert Mod 8TB
radiosChecked()
- argument obj not used
- variable radio undefined
- for-loop exited in first run (doing a for-loop at all is pointless along with the return statements)

function Checkedanswers()
- unknown property "att"
- if you're only passing "this" as parameter, you may as well omit the parameter and call "this" inside the function
Apr 10 '09 #4
so what can i do to fix it?
thanks for help
Apr 10 '09 #5
acoder
16,027 Expert Mod 8TB
There are quite a few hints about what you can do, the most obvious being that you need to change obj to radio in radiosChecked. You can omit 'this' when calling checkAnswers and use 'this' within the function:
Expand|Select|Wrap|Line Numbers
  1. if (!radiosChecked(this.elements["att"])) ...
Apr 13 '09 #6
thanks for hint i get it
Apr 13 '09 #7

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

Similar topics

1
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there...
10
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group...
6
by: sakms | last post by:
I am attempting to validate radio buttons in Netscape with JavaScript. Everything works excellent in Explorer, but refuses to work in Netscape (all versions). =========== JAVASCRIPT CODE...
1
by: Jay | last post by:
I need to validate 21 sets of radio buttons before submission to the server for calculation and storage. Is it best to validate on the client side using javascript or to validate on the server...
2
by: NishSF | last post by:
Would anyone have any suggestions/javascript code so that if one clicks the Radio Button "Yes" below he has the option of selecting any of the six CheckBox below. If the user clicks on Radio Button...
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...
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...
2
by: runway27 | last post by:
i am using a self submitting form <form action="<?php echo $_SERVER; ?>" method="POST" id="test2" name="test1"> i need to do a validation of textfields, checkboxes, radio buttons i am able...
5
by: satyabhaskar | last post by:
hi all, In my web page i have created radio buttons dynamically on to the page .....following is my code string Course, Semester, Section; int rowsCount; string con =...
3
by: 1051109210 | last post by:
<table class="special3" align="left" width="75%" height="65%" > <form> <table width="50%" align="center"> <tr align="right"> <td></td> <td><a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.