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

Posted on 2011-05-11
Last Modified: 2012-05-11
In this form:

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.
Question by:phillystyle123
    LVL 13

    Assisted Solution

    Assuming your form name is testform and radio buttons name is rbutton,

    <script type="text/javascript">
        var frm=document.testform;
            //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.
    LVL 81

    Assisted Solution

    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


    Accepted Solution

    function validate(){
                               if(document.getElementById('OneTime_0').checked )
                                  alert('Enter Billing Start Day');
                                                document.frm1.Billing_Start_Date_Day.focus();return false;
                                  alert('Enter Billing Start Month');
                                  document.frm1.Billing_Start_Date_Month.focus();return false;
                                  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(""){alert("An email address is required to process this transaction ");;return false;}      


    Author Closing Comment

    Found the exact answer in another of my posts - but the logic here is correct

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    A common challenge, or question, when working with two calendar dates is: What is the difference between the specified days? As is frequently the case, the answer is: It depends... What kind of difference do you want? Given two date obje…
    This article shows how to read a single webpage's HTML into a string variable, and it also shows how to automate a sequence so you can read and process a list of webpages.  I was tasked with reading and parsing a series of webpages to collect some s…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now