Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] radio button form validation issue


  • From: peter at brunone.com (Peter Brunone)
  • Subject: [Javascript] radio button form validation issue
  • Date: Fri Apr 25 15:16:56 2003

Travis,

	I asked almost the same question earlier this week.  It seems we both have
the same mental block (cleared courtesy of Chris Tifer).

	What you need to do, rather than referencing the individual elements of the
form (which have no length), is to get the name of the particular radio
group you want to evaluate as an array.  In this case, the changes I've made
below should do the trick.  You want to refer to the element by name rather
than by index within the form, so that you can treat it as an array of
like-named elements instead of as a single element.

Cheers,

Peter

-----Original Message-----
From: javascript-bounces@xxxxxxxxxx On Behalf Of Falls, Travis D

Here is my script, the mySurvey[i] is evaluating to undefined, but if I
reference the actual name of the radio button I get the proper amount.  any
ideas?


<script language="JavaScript" type="text/javascript">
    function validateForm(mySurvey){
         for(i=0; i<mySurvey.length; i++){

              if(mySurvey[i].type=="radio"){
                   var isSelected=false;

		       currentName = mySurvey[i].name // added

                   currentField = mySurvey.elements[currentName]; //added

                   for(u=0; u < currentField.length; u++){ // changed
                        if(currentField[u].checked){ // changed
                             alert("correct");
                             isSelected=true;
                             return true;
                        }//ends if
                        else{
                             alert("inCSorrect");
                        }
                   }//ends for u
               }//ends if radio
         } //ends for i
     return false;
    }//ends function
</script>

__________________________________________________________

Travis D. Falls