bootstrap multiselect get selected values

前端 未结 7 1535
难免孤独
难免孤独 2021-01-31 16:39

How do I get back on onChange all selected values in my multiselect dropdown. Used plugin here. Trying to use the following but I think I\'m on the wrong track

$         


        
7条回答
  •  庸人自扰
    2021-01-31 17:10

    In your Html page please add

    
    
      
        
        
        
        Test the multiselect with ajax
    
        
        
        
        
        
    
        
        
        
      
      
        





    result

    In your ajax.js page please add

    $(document).ready(function () {
      $(".btnSubmit").on('click',(function(event) {
        var formData = new FormData($('#myForm')[0]);
        $.ajax({
          url: "action.php",
          type: "POST",
          data: formData,
          contentType: false,
          cache: false,
          processData:false,
          success: function(data)
          {
            $("#result").html(data);
    
            // To clear the selected options
            var select = $("#example-getting-started");
            select.children().remove();
            if (data.d) {
              $(data.d).each(function(key,value) {
                $("#example-getting-started").append($("").val(value.State_id).html(value.State_name));
              });
            }
            $('#example-getting-started').multiselect({includeSelectAllOption: true});
            $("#example-getting-started").multiselect('refresh');
    
          },
          error: function()
          {
            console.log("failed to send the data");
          }
        });
      }));
    });
    

    In your action.php page add

      echo "You selected :";
    
      for($i=0;$i<=count($_POST['categories']);$i++){
    
        echo $_POST['categories'][$i]."
    "; }

提交回复
热议问题