Click here to Skip to main content
16,007,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using this script I want to validate a radio group and when the error message comes up I want the cursor to go the radio input that is in error. Instead it resets the form. Could you tell me where my code has gone wrong?
theForm.Cover_Style.focus();

is what i added.


JavaScript
var radioSelected = false;
for (i = 0;  i < theForm.Cover_Style.length;  i++)
   {
   if (theForm.Cover_Style[i].checked)
      radioSelected = true;
   }
if (!radioSelected)
   {
   alert("Please select a \"Cover Style (Soft Cover or Hard Cover)\.");
   theForm.Cover_Style.focus();
   return (false);
   }


[edit]Subject - Try to describe your problem briefly. "Beginner needs help" doesn't help us decide if we know about your problem before we take the time to open the link.
Code block add to improve readability - OriginalGriff[/edit]
Posted
Updated 23-Nov-10 6:00am
v2

1 solution

Instead of doing that, set a radio item in the group as selected and the need to validate whether or not a radio button is checked is eliminated. If you have to, add a radio button that reads "Not selected", or somethig appropriate, and select it by default.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900