Click here to Skip to main content
15,795,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
So i wanted to disable some of my items from the dropdown list based on the Action.
Eg : if action =1, then disable the Type ="Red" , if action = 2, then disable the Type="Blue" in the dropdownlist.

And is this the correct way to put multiple values in the ??

What I have tried:

<div class="col-sm-5 form-group">
      <label for="ActionName" class="col-form-label"> Action:</label>
          <select class="form-control" name="ActionName">
            <option value="">Select Action</option>
                 @foreach($action as $act)
                  <option value="{{$act->Item}}">Select Action</option>
<div class="col-sm-5 form-group">
     <label for="ID" class="col-form-label">User Name:</label>
       <select class="select form-control" name="ID" id="ID" multiple="multiple">
            $result = $_POST['ID'];
            $result_explode = explode('|', $result);
            echo "ID: ". $result_explode[0]."<br />";
            echo "Type: ". $result_explode[1]."<br />";

            @foreach($user as $usr)
            <option value="{{$usr->ID}}|{{$usr->Type}}">Select</option>
       </select>  </div>

        var obj = {};
        obj["ActionName"] = $("option:selected", this).val();

        ajaxJsonProcess("post", urlPathID, obj, function(inDat){
            $("[name='ID']").append("<option value=''>Select</option>");
            $.each(inDat, function(index, element) {
                $("[name='ID']").append("<option value='" + element.ID+ "'>" + element.ID+ "</option>");

Updated 14-Oct-20 3:20am
Sandeep Mewara 13-Oct-20 8:39am    
There are two ways you can do it:
1. Either you load only relevant options on action value - thus keep the items vary (dropdown items count adjust at runtime)
2. Keep fixed static dropdownlist and set the options enable/disable based on action value (dropdown items count fixed)

1 solution

$("[name='ID']").append("<option disabled value=''>Select</option>");
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900