View Single Post
  #5 (permalink)  
Old Apr 23rd, 2008, 23:23
psycho wolvesbane psycho wolvesbane is offline
Junior Member
Join Date: Feb 2008
Location: England
Age: 21
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Validation code problem

The form element Sizes which is a radio button. Since it's being dynamically added depending on the mysql database entries it could have multiple radio buttons grouped under the same name, Sizes, making it an array.

However if there is only the 1 entry in the database the single radio button doesn't become an array and the validation can't do anything about it as it was written to handle arrays only.

Edit:

Anyway I got help from another form

Code: Select all
   var checked = false; 
   var Sizes = document.BuyProduct.Sizes;

   if (Sizes.length){
      for (var i=0; i<Sizes.length; i++)  
      {  
         if (Sizes[i].checked) {  
         checked = true;   
         }  
      }
   }
   else if(Sizes.checked)
   {
      checked=true;
   }
 
   if(!checked) 
   {  
      Errors++
      document.getElementById('mySpan1a').style.display='block';
      document.getElementById('mySpan1a').innerHTML='Please Select a Size!';
      document.getElementById('mySpan1b').style.display='inline';
      document.getElementById('mySpan1b').innerHTML='! ';
   }
   else
   {
      document.getElementById('mySpan1a').style.display='none';
      document.getElementById('mySpan1a').innerHTML='';
      document.getElementById('mySpan1b').style.display='none';
      document.getElementById('mySpan1b').innerHTML='';
   }

Last edited by psycho wolvesbane; Apr 23rd, 2008 at 23:27.
Reply With Quote