Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9167811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:28:55+00:00 2026-06-17T15:28:55+00:00

I have two multi select boxes one for country list and one for state

  • 0

I have two multi select boxes one for country list and one for state list

<select multiple="multiple" name="country[]" id="country" >
      <option value="0">Select a Country</option>


  <?php 
    foreach($country_list as $key=>$value){
    echo "<option value=\"$key\"";
      if($html['Country Name']==$key|| $row['Country Name']==$key){
       echo ' selected="selected"';
      }
    echo ">$value</option>\n";                                     
    }?>
</select>


<select multiple="multiple" name="state[]" id="state">
      <option value="">Select a State</option>
      <?php 
        foreach($state_list as $key=>$value){
        echo "<option value=\"$key\"";
          if($html['state']==$key|| $row['state']==$key){
            echo ' selected="selected"';
          }
        echo ">$value</option>\n";                                     

        }?>
    </select>

I have this javascript code

window.onload = function() {
    var selectCountry = document.getElementById('country');
    selectCountry.onchange = function() {
        document.getElementById('state').disabled = (selectCountry.value != 'USA')? true : false;
    };
};

This code disables the select box when countries other than USA is selected. I want it to be disabled even when more than 1 country is selected in the first drop down (If user selects USA and CAN, it should be disabled too). Any suggestions. I have the working code in Jquery, but my server doesn’t seem to support Jquery at all, I want it in Traditional JS.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:28:56+00:00Added an answer on June 17, 2026 at 3:28 pm

    Just go through all selected options and check if one of them has a value equal to USA:

    selectCountry.onchange = function() {
            var disabled = false;
            for(var i = 0; i < this.options.length; i++){
                if(this.options[i].selected && this.options[i].value == 'USA') {
                    disabled =true;
                    break
                }
            }
            document.getElementById('state').disabled = disabled;
        };
    

    Note that this will point to selectCountry element.

    Also, server never “support” jquery. You just put jquery.js file under website directory and add a link to it on your website.

    You can get slightly simpler code by using selecteOptions property, but can’t find if it is supported by all browsers:

    var disabled = false;
        for(var i = 0; i<this.selectedOptions.length; i++){
            if(this.selectedOptions[i].value == "3") {
                disabled =true;
                 break
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two multi select boxes one for country list and one for state
`<select multiple=multiple name=state[] id=state> <option value=>Select a State</option> <?php foreach($state_list as $key=>$value){ echo <option
I have two multi-select list boxes; one with months and one with years such
I have a multi dimensional array in PHP. $f = array('one' => array(*doesntmatter*), two
I have two multi-select lists in HTML - one of categories, and another of
I'm working on a control where you'd have two multi-select lists with collections of
I have a table called meta , with two columns name and value .
I have a Maven multi-module project and I need two different parent POMs in
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
I have two classes (MVC view model) which inherits from one abstract base class.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.