0

I trying to do some validation on a form with radio buttons in it. I can get the text elements to work fine but the radio buttons don't seem to like me.

function validateAll(theForm)
    {   
        var err=0;
        var fields;
        for (var i=0; i<theForm.elements.length; i++)
        {

            fields =theForm.elements[i];
            if(fields.type == "text" || fields.type == "textarea")
            {
                if(fields.value == "" || fields.value == null){

                err++;
                validateText(fields.id);

            }
                }

            else if(fields.type == "radio"){


                validateRadio(fields)

            }
        }
        if(err > 0){return;}else{document.myform.submit();}
}


function validateText(id)
    {

    var x=document.forms["myForm"][id].value;
if (x==null || x=="")
  {
  var text = id+"Text";
  document.getElementById(text).style.visibility ="visible";
    return;
  }else {

     var text = id+"Text";
  document.getElementById(text).style.visibility="hidden";
      return;

      }


    }

    function validateRadio(radios)
    {

        var id = radios.id;
        var text;
        for (i = -1; i < radios.length; ++i)
    {
        if (radios[i].checked) {

        text = id+"Text";
        document.getElementById(text).style.visibility="hidden";
        return true
    }}

    text = id+"Text";
    alert(text);
  document.getElementById(text).style.visibility ="visible";
    return false;


    }

I am just calling it with a input button. Any ideas on why its not working? It turns the text on find but dose not turn it off.

4

0 回答 0