if a radiobutton is checked, 4 dropdowns have to be selected from

In this form:

https://goodsam.org/giving-aim-cr2/form.php

select the radio button:
"I would like to make my donation a recurring gift"

I need to require the user to select something from all 4 of those drop downs that appear when the radio button is checked.
phillystyle123Asked:
Who is Participating?
 
phillystyle123Connect With a Mentor Author Commented:
function validate(){
     
     
      if(checkCheckBoxes()){
     
                          
                         
                           if(document.getElementById('OneTime_0').checked )
                  {
                        if(document.frm1.Billing_Start_Date_Day.value=="")
                        {
                              alert('Enter Billing Start Day');
                                            document.frm1.Billing_Start_Date_Day.focus();return false;
                        }
                                    if(document.frm1.Billing_Start_Date_Month.value=="")
                        {
                              alert('Enter Billing Start Month');
                              document.frm1.Billing_Start_Date_Month.focus();return false;
                        }
                                    if(document.frm1.Billing_Start_Date_Year.value=="")
                        {
                              alert('Enter Billing Start Year');
                              document.frm1.Billing_Start_Date_Year.focus();return false;
                        }
                  }  
                          if(document.getElementById('radDurationEnd1').checked )
                  {
                        if( !/^\d+$/.test(document.frm1.totalOccurrences.value) )
                        {
                              alert('End subscription after how many months? - Please enter number OR click No End Date ');
                              return false;
                        }
                                    
                  }      
     
            if(document.frm1.Name_on_card.value==""){alert("Please  input your first name ");document.frm1.Name_on_card.focus();return false;}
                 
            if(document.frm1.cardnumber.value==""){alert("Please  input your credit card number ");document.frm1.cardnumber.focus();return false;}      
            if(document.frm1.expmonth.value==""){alert("Please  specify month expiration ");document.frm1.expmonth.focus();return false;}
            if(document.frm1.expyear.value==""){alert("Please  specify year expiration ");document.frm1.expyear.focus();return false;}
           
            if(document.frm1.First_Name.value==""){alert("Please  input your first name ");document.frm1.First_Name.focus();return false;}
            if(document.frm1.Last_Name.value==""){alert("Please  input your last name ");document.frm1.Last_Name.focus();return false;}
           
            if(document.frm1.email.value==""){alert("An email address is required to process this transaction ");document.frm1.email.focus();return false;}      
           
           
           
           
           
            document.frm1.act.value="create_payment";
            document.frm1.submit();
      }

}
0
 
ansudhindraConnect With a Mentor Commented:
Assuming your form name is testform and radio buttons name is rbutton,

<script type="text/javascript">
    var frm=document.testform;
    if(frm.rbutton[1].checked){
        //second radio button is selected.
        //do required validation for dropdowns somethign like below.
       if(frm.dropdown1.value=="" || frm.dropdown2.value==""){
          alert("Select value in the dropdowns");
          return false;
       }
    } else {
       //Assuming first radio button is selected.
    }    
<script>
0
 
leakim971Connect With a Mentor PluritechnicianCommented:
Set the onsubmit attribute of your form :

<form method="POST" action="submitpayment.php" name="frm1" onsubmit="return validate();">

Open in new window


And your validate function (or the part you're looking for) :

function $(id)  { return document.getElementById(id); }
function $name(name)  { return document.getElementsByName(name)[0]; }

function validate() {
    if( $("OneTime_0").checked && ($("Billing_Start_Date_Day").selectedIndex==0 || $name("Billing_Start_Date_Month").selectedIndex==0 || $("Billing_Start_Date_Year").selectedIndex==0 || $("p_duration").selectedInde==0) ) {
         alert("Please complete Recurring Billing Info section!!!");
         return false;
    }
    return true;
}

Open in new window


0
 
phillystyle123Author Commented:
Found the exact answer in another of my posts - but the logic here is correct
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.