Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I validate Radio Group with existing validation script?

Status
Not open for further replies.

dfreem5

Technical User
Feb 2, 2003
2
US
HiJS Gurus!
I'm currenlty using the script found here: and I have it working for everything but a radio group - guess it's one that needs customizing.

Any ideas?

Deb
 
Try adding this code to the validator.js file:
Code:
function RadioValueFieldValidator(item, param)
{
  for (var i=0; i < item.length; i++)  {
    if (item[i].checked)  {
      return true ;
    }
  }

  // if here, no items checked
  return false ;
}
and attach it to your radio button list as you would a normal event handler with this object.

I think it will work; I never tested it :( However, if you need to validate the radio controls on a form, you could use this syntax also:
Code:
function validateRadioGroup(frmObject) {
  for (var i=0; i < item.length; i++)  {
    if (item[i].checked)  {
      return true ;
    }
  }

  // if we're here, no radio buttons checked
  return false ;
}
and use it like this:
Code:
var item = document.forms['form name'].<radio group name> ;
if (!validateRadioGroup(item)) {
  alert("No radio buttons checked") ;
}
else {
  alert("OK") ;
}


Greg
 
Thanks Greg for jumping in.
I cannot get either to work. I would prefer the first method, as it would generate consistent validation results. Checkit out here: Click submit w/o completing any fields.
I would like the 'R' to appear next to the Business Entity fieldset.

I almost think it might be working, but does not have a pleace to display the 'R'...
What do you think?

The 2nd solution you offer: Maybe I'm placing it in the wrong place.. but I have either one or the other validation working.
I cant seem to get them both going at the same time.
Make any sense?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top