Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How do I validate a radio button and checkbox?

soxchicksoxchick Member Posts: 6
I have a form on an .asp page that I am validating. Everything works fine, except I am not sure how to validate the radio button and checkbox. I want to make these fields required. There are two radio buttons with the same name, and values of Yes and No. The checkboxes are named location, and there are about 32 different options, with individual values. This is the code within my javascript validation function that is called when the submit button is clicked(taxable is the name of my 2 radio buttons and location is the checkbox name):

if (theForm.taxable.selected)
{
alert("Please select a "Taxable" option.");
theForm.taxable.focus();
return false;
}

if (theForm.location.checked)
{
return true;
}
Else
{
alert("Please select at least one "Stocking Location" option.");
theForm.location.focus();
return false;
}

My text fields are all validating properly, so I know the function is set up correctly. I am just not sure how (if) I can validate the radio buttons and check boxes.

Comments

  • mac_doggiemac_doggie Member Posts: 488
    This post has been deleted.
  • navdmknavdmk Member Posts: 2
    : I have a form on an .asp page that I am validating. Everything works fine, except I am not sure how to validate the radio button and checkbox. I want to make these fields required. There are two radio buttons with the same name, and values of Yes and No. The checkboxes are named location, and there are about 32 different options, with individual values. This is the code within my javascript validation function that is called when the submit button is clicked(taxable is the name of my 2 radio buttons and location is the checkbox name):
    :
    : if (theForm.taxable.selected)
    : {
    : alert("Please select a "Taxable" option.");
    : theForm.taxable.focus();
    : return false;
    : }
    :
    : if (theForm.location.checked)
    : {
    : return true;
    : }
    : Else
    : {
    : alert("Please select at least one "Stocking Location" option.");
    : theForm.location.focus();
    : return false;
    : }
    :
    : My text fields are all validating properly, so I know the function is set up correctly. I am just not sure how (if) I can validate the radio buttons and check boxes.
    :


    try this
    function validateForm(form1)
    {

    if((form1.option1[0].checked==false) && (form1.option1[1].checked==false))
    {
    alert("Please Tick the desired option");
    form1.option1[0].focus();
    return false;
    }
    }
Sign In or Register to comment.