www.webdeveloper.com
Results 1 to 8 of 8

Thread: How to disable the multi select dropdown box

  1. #1
    Join Date
    Dec 2008
    Posts
    17

    How to disable the multi select dropdown box

    Hi
    I have two dropdown box. select ID="Country" and "State".
    dropdown box is a Multiselect Dropdownbox which has a check box
    associated with it. This drop down box is used to select multiple states at
    a time. Once selected , it gets displayed in top row.


    Dropdown Box Country has three values. ALL, USA and FOREIGN.

    Now My question is
    whenALL or FOREIGN is selected from DROPDOWN Box Country then Multiselect DropDown box State should be disabled.

    I have coded in follwoing way but is not working.

    <script language="javascript" src="<%= request.getContextPath() %>/js/jquery-1.2.6.min.js" type="text/JavaScript"></script>

    <script type="text/javascript">
    jQuery(document).ready(function(){
    jQuery('#Country').click(function(){
    if((jQuery("#Country").val() == "USA")) {
    jQuery('#State').attr("disabled", false);

    }
    else{
    jQuery('#State').attr("disabled", true);
    }
    return false;
    });


    How do I implement this Jquery or Javascript.

    Your help is appreciated.

    Thanks
    dgm

  2. #2
    Join Date
    May 2006
    Location
    Odenton, MD
    Posts
    1,449
    as for jQuery i don't know because i has never used it. however, here is how you do it without a framework:
    Code:
    <select onchange="
    if(this.value != 'USA')document.getElementById('State').disabled = true;
    else document.getElementById('State').disabled = false;">
    ...</select>

  3. #3
    Join Date
    Jul 2003
    Location
    The City of Roses
    Posts
    2,503
    dgm, if you keep your code well formatted, then spotting the error will be obvious.

    Code:
    jQuery(document).ready(function(){
    	jQuery('#Country').click(function(){
    		if((jQuery("#Country").val() == "USA")) {
    			jQuery('#State').attr("disabled", false);
    		}
    		else{
    			jQuery('#State').attr("disabled", true);
    		}
    		return false;
    	<-- missing something here
    });
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  4. #4
    Join Date
    Dec 2008
    Posts
    17

    Disabling multi column dropdown box using JQUERY

    Thanks for the attention the guys.

    My Jquery works for Single column dropdown box but does not work for Multi select dropdown box. Multiselect means multiple values can be selected from the dropdown. I want to disable this but I could not do it.

    Here is my code for Dropdown box.

    <fieldset><legend align="left">State Selection</legend>
    Include&nbsp;
    <span id="stateSelectionPlaceHolder">Loading...</span>
    <select id="stateSelection" name="stateSelection" multiple="multiple" size="6" style='display: none;'>
    <option value="AL"
    >ALABAMA</option><option value="AK"
    >ALASKA</option><option value="AS"
    >AMERICAN SAMOA</option><option value="AZ"
    >ARIZONA</option><option value="AR"
    >ARKANSAS</option><option value="AA"
    >ARMED FORCES</option><option value="AE"
    >ARMED FORCES OTHER</option><option value="AP"
    >ARMED FORCES PACIFIC</option><option value="CA"
    >CALIFORNIA</option><option value="CO"
    >COLORADO</option><option value="CT"
    >CONNECTICUT</option><option value="DE"
    >DELAWARE</option><option value="DC"
    >DISTRICT OF COLUMBIA</option><option value="FL"
    >FLORIDA</option><option value="FC"
    >FOREIGN COUNTRY</option><option value="GA"
    >GEORGIA</option><option value="GU"
    >GUAM</option><option value="HI"
    >HAWAII</option><option value="ID"
    >IDAHO</option><option value="IL"
    >ILLINOIS</option><option value="IN"
    >INDIANA</option><option value="IA"
    >IOWA</option><option value="KS"
    >KANSAS</option><option value="KY"
    >KENTUCKY</option><option value="LA"
    >LOUISIANA</option><option value="ME"
    >MAINE</option><option value="MD"
    >MARYLAND</option><option value="MA"
    >MASSACHUSETTS</option><option value="MI"
    >MICHIGAN</option><option value="MN"
    >MINNESOTA</option><option value="MS"
    >MISSISSIPPI</option><option value="MO"
    >MISSOURI</option><option value="MT"
    >MONTANA</option><option value="CM"
    >N MARIANA ISLANDS</option><option value="NE"
    >NEBRASKA</option><option value="NV"
    >NEVADA</option><option value="NH"
    >NEW HAMPSHIRE</option><option value="NJ"
    >NEW JERSEY</option><option value="NM"
    >NEW MEXICO</option><option value="NY"
    >NEW YORK</option><option value="NC"
    >NORTH CAROLINA</option><option value="ND"
    >NORTH DAKOTA</option><option value="OH"
    >OHIO</option><option value="OK"
    >OKLAHOMA</option><option value="OR"
    >OREGON</option><option value="PA"
    >PENNSYLVANIA</option><option value="PR"
    >PUERTO RICO</option><option value="RI"
    >RHODE ISLAND</option><option value="MP"
    >SAIPAN NORTHERN MARINA IS</option><option value="SC"
    >SOUTH CAROLINA</option><option value="SD"
    >SOUTH DAKOTA</option><option value="TN"
    >TENNESSEE</option><option value="TX"
    >TEXAS</option><option value="UT"
    >UTAH</option><option value="VT"
    >VERMONT</option><option value="VI"
    >VIRGIN ISLANDS</option><option value="VA"
    >VIRGINIA</option><option value="WA"
    >WASHINGTON</option><option value="WV"
    >WEST VIRGINIA</option><option value="WI"
    >WISCONSIN</option><option value="WY"
    >WYOMING</option>
    </select>
    </fieldset>



    I wrote the following in Jquery but does not work.

    jQuery(document).ready(function(){
    jQuery('#stateSelection').onchange(function(){
    jQuery('#stateSelection').attr("disabled", "disabled");
    }
    });


    This works for Single selection Dropdown box.

    Thanks
    Digambar

  5. #5
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,434

    Talking

    Remove the RED in the following line:
    Code:
    <select id="stateSelection" name="stateSelection" multiple="multiple" size="6" style='display: none;'>

  6. #6
    Join Date
    Dec 2008
    Posts
    17
    Hi
    I need to keep multiple for my thing to work. If I remove Multiple, it does not work and does not display the states.

    Any expert please help.

    Thanks

  7. #7
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,434

    Question

    Quote Originally Posted by dgm View Post
    Hi
    I need to keep multiple for my thing to work. If I remove Multiple, it does not work and does not display the states.

    Any expert please help.

    Thanks
    In your post #1 you said:
    My Jquery works for Single column dropdown box but does not work for Multi select dropdown box. Multiselect means multiple values can be selected from the dropdown. I want to disable this but I could not do it.
    You need to keep your requests consistent.

  8. #8
    Join Date
    Dec 2008
    Posts
    17

    jquery disable a Multi Column Multi select Dropdown box.

    Hi
    This is a Multiple column dropdown box. This drop down has a checkbox and state name side by side. We can select multple state at a time.

    This has Jqury plugin without which it does not work.
    Following is present.

    jQuery("#stateSelection").multiSelect({ oneOrMoreSelected: '*',
    noneSelected : 'Select options (Default = *ALL)' });



    I am trying to disable it when Country selecred other than USA.

    Any Idea how to disable.

    jQuery("#countrySelection").change(function() {
    if ( jQuery("#cntry").val() != "USA")
    jQuery('#stateSelection').attr("disabled", true);
    else
    jQuery('#stateSelection').attr("disabled", false);
    });

    This above is not working to disable the stateSelection. Is there anything required due to Multiselect Plugin.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles