[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

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.
0
phillystyle123
Asked:
phillystyle123
  • 2
3 Solutions
 
ansudhindraCommented:
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
 
leakim971PluritechnicianCommented:
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:
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
 
phillystyle123Author Commented:
Found the exact answer in another of my posts - but the logic here is correct
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now