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

validate <input type="radio">

17
I'm working on an assignment for school where we're working with JavaScript (I'm only allowed to use JavaScript) to validate a form for a payment page. It's my first time working with JavaScript so and I feel a bit lost..i need to link htmp radio buttons and javascript with a Calculate button


thml code

Expand|Select|Wrap|Line Numbers
  1. <td><input type="text" id="text7" name="fexpirydate" placeholder="22/08/2030" maxlength="30">
  2.         <tr/>
  3.         <tr>
  4.         <td><input type="radio" name="gender" value="Cash" checked><strong>Cash</strong></td>
  5.         </tr>
  6.         <tr>
  7.         <td><input type="radio" name="gender" value="Ecocash" checked><strong>Ecocash</strong></td>
  8.         </tr>
  9.         <tr>
  10.         <td><input type="radio" name="gender" value="Swipe" checked><strong>Swipe</strong></td>
  11.         </tr><br><br><br>
Sep 10 '19 #1
3 1622
gits
5,390 Expert Mod 4TB
what exactly should happen in the program here and what have you done so far to solve it?
Sep 10 '19 #2
Expand|Select|Wrap|Line Numbers
  1. <form name="form1" action="#" onsubmit="return validateForm()" method="post"> 
  2.     First time visitor?:<br/>
  3.             <label for="s1">Yes</label>
  4.             <input type="radio" id="radio1" name="yesno" value="1"/>
  5.             <br/>
  6.             <label for="s2">No</label>
  7.             <input type="radio" id="radio2" name="yesno" value="2"/>
  8.  
  9.             <br/>       
  10.  
  11.     <input type="submit" value="Submit"><br/>
  12.     </form>
  13.  


Expand|Select|Wrap|Line Numbers
  1. function validateForm() {
  2.     var radios = document.getElementsByName("yesno");
  3.     var formValid = false;
  4.  
  5.     var i = 0;
  6.     while (!formValid && i < radios.length) {
  7.         if (radios[i].checked) formValid = true;
  8.         i++;        
  9.     }
  10.  
  11.     if (!formValid) alert("Must check some option!");
  12.     return formValid;
  13. }
Sep 16 '19 #3
gits
5,390 Expert Mod 4TB
throwing out some code without knowing what the exact problem is is plain guesswork. While the OP is already asking because he/she is lost - with no further elaboration of that shown code it probably even wont help much - the answer could even be 42.

Besides that its pretty sub-optimal to do validations like that - since it requires DOM operations. its much more optimal when using events to update a state - you will see that when you have pages with lots of elements that you are validating the way you propose here.
Sep 16 '19 #4

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

Similar topics

1
by: aevans1108 | last post by:
Greetings All If this is the wrong place to post this question, please give me a push in the right direction. Thanks. I know there has to be a simpler way to do this, but this is as simple a...
0
by: SHC | last post by:
Hi all, I have a VC++ .NET 2003 - Windows XP Pro PC. I created a Win32 console application in my VC++ .NET 2003 and copied validateDOM.cpp, books.xml and books.xsd (see the attached files below)...
5
by: Jim Heavey | last post by:
When should you use the Page.Validate() method? I thought you would use this method if you have some Server side validation (CustomControl's) you wanted to use and this would cause them to be...
11
by: jjbutera | last post by:
I know how to use the ErrorProvider in my winforms..or do I? I validate the values and set the ErrorProvider in the validating event. If not valid, I set e.Cancel = True. I clear the ErrorProvider...
0
by: Marc Scheuner | last post by:
Folks, I'm faced with a dilemma here - I have an XML document and for part of it, I have an XSD schema to validate it - but not for the rest of it. Can I still validate at least part of the...
4
by: Brybot | last post by:
I have a form that i've split up into multiple asp:panels, each panel has a number of validators which work correctly. At on the last panel, i want to commit the data collected to a database. I...
24
by: Mike Hofer | last post by:
Please forgive the cross-post to multiple forums. I did it intentionally, but I *think* it was appropriate given the nature of my question. I'm working on an open source code library to help...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.