HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old March 11th, 2005, 09:00 AM
bears13 bears13 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 21 bears13 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 22 m
Reputation Power: 0
Validating Radio Buttons

Does anyone know how to validate a selection of two radio buttons. But not a IF statement for just the two.
Meaning if later on there were more radio button options added the code wouldn't need fixed just the readio button?

Thanks

Reply With Quote
  #2  
Old March 11th, 2005, 12:00 PM
lewy's Avatar
lewy lewy is offline
Alter Ego Wizard
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Edinburg Tx
Posts: 4,381 lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 1009 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 1 Day 23 h 7 m 43 sec
Reputation Power: 1488
Code:
<html>
   <head>  
     <script language="JavaScript">   
   
     //this function takes two parameters, one, the radio group name and
     //the group name or any meaningful message in quotes in the function call.
     //you can omit the latter if you don't want the generic function to 
     //tell you which group was missing a button clicked
     function validateRadio(group,grpname) 
     {
   	for (var i=0; i < group.length; i++) 
   	{
   	  if (group[i].checked) 
   	  { i = group.length;		
   		return true;
   	  }
   	}
   	alert("No Radio Button Was Clicked On Group " + grpname + "\nMake Sure you Click At Least One");
   	return false;
      }
   
     function validate()
     {
   	var group1 = document.forms[0].elements("Group1");
   	var group2 = document.forms[0].elements("Group2");
   
   	if (validateRadio(group1,"Group1") && validateRadio(group2,"Group2"))
   	return true;
   	else
   		return false;
     }
     </script>	
   
   </head>
   <body>
   <form action="tst.asp" method="post" onSubmit="return validate();">
   <input type="radio" name="Group1" value="1">
   <input type="radio" name="Group1" value="2">
   <input type="radio" name="Group1" value="3">
   <br>
   
   <input type="radio" name="Group2" value="1">
   <input type="radio" name="Group2" value="2">
   <input type="radio" name="Group2" value="3">
   <input type="submit" value="Submit">
   </form>
   </body>
   </html>

Above is an example of a generic radio button check function.
If you need to add more validation, you need to add more to the validate function for other radio button groups you may need.
Feel free to post any additional questions you may have
Comments on this post
nofriends agrees: nice piece of code
__________________
................... ASCII and ye shall receive ..................
Knowledge is the only resource on earth that multiplies when shared


Support the Shemzilla Project
Powered by C#

Reply With Quote
  #3  
Old March 11th, 2005, 12:14 PM
Memnoch's Avatar
Memnoch Memnoch is online now
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 15 m 35 sec
Reputation Power: 470
bears13,
In the future, try doing a search first, before posting a question.
If you had searched for "Validating Radio Buttons" you would have found 9 different threads, that are similar to your question.

Reply With Quote
  #4  
Old March 12th, 2005, 04:28 PM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 46th Plane (27500 - 27999 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,628 Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)  Folding Points: 372965 Folding Title: Super Ultimate Folder - Level 1Folding Points: 372965 Folding Title: Super Ultimate Folder - Level 1Folding Points: 372965 Folding Title: Super Ultimate Folder - Level 1Folding Points: 372965 Folding Title: Super Ultimate Folder - Level 1Folding Points: 372965 Folding Title: Super Ultimate Folder - Level 1Folding Points: 372965 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 2 h 23 m 57 sec
Reputation Power: 1902
...and this is html/javascript issue - moved to the HTML forum.

Reply With Quote
  #5  
Old March 13th, 2005, 01:52 PM
bears13 bears13 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 21 bears13 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 22 m
Reputation Power: 0
I should have been more specific. But I'm writing in vbscript. I have the logic just dont have the idea to write it

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > Validating Radio Buttons


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT