473,657 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

validate <input type="radio">

17 New Member
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 1633
gits
5,390 Recognized Expert Moderator Expert
what exactly should happen in the program here and what have you done so far to solve it?
Sep 10 '19 #2
parth123
4 New Member
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 Recognized Expert Moderator Expert
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
9104
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 way as I could come up with. Yes, it's obvious I don't know what I'm doing. I'm creating an XSD string and an XML string at runtime (ie: NOT read
0
4575
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) from Microfost MSDN Library for my project "validateXML". When I did "Build" on my project, I got the following fatal error C1010: c:\Documents and Settings\SHC\My Documents\Visual Studio Projects\valoidateDOM\valoidateDOM.cpp(273): fatal error...
5
2524
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 invoked. I am probably wrong about that. If I am suppose to use this function, the edits seemed to be invoked even when you have pressed the cancel and the "CausesValidation" is set to false. Is there a way to get around this (might just be an...
11
11754
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 in the validated event. Is there a way to know if all validated controls pass validation when the user clicks an OK button? In ASP.Net there's the Page.IsValid method. Is there something similar in winforms, or do I still have to write an...
0
2641
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 XML document? I was hoping to use the XmlDocument.Validate(ValidationEventHandler, XmlNode) method for that - doesn't seem to work...
4
2590
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 figured since all the panel data is still being sent through the postbacks, instead of using Sessions, or HttpContext, I could just take the values from the textboxes. This all works fine, except for security. I realized that I could inject...
24
2098
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 automate and clean up parameter validation code. It's almost ready to go into open beta. But one last little glitch is holding me up, and that would be the name of the factory class that serves as the entry point into the library: Validate.
0
8319
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8837
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8612
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6175
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.