0

Hi I have multiple banks which user can select one or multiple.I am sending data through ajax but the problem is I get the first bank selected when I dd my request,I want the value of every bank which has been selected by the user. below is my code.I have different other components as well.

bankSelector.blade

                    <input
                        id="bank_{{$item['code']}}"
                        name="banks"
                        class="form-check-input bank"
                        type="checkbox"
                        value="{{$item['code']}}"
                        checked/>

ajax.js

              $('form').submit(function(e){
              e.preventDefault();
              let formData = new FormData(this)
            
        $.ajax({
          url: "/product/save",
          type: "POST",
          data: formData,
          contentType: false,
          processData: false,
          headers: {
            "X-CSRF-TOKEN": $('meta[name="_token"]').attr("content"),
          },
          success: function (data) {

            // show("#step8");
          },
          error: function () {

        },
    });
});

1 Answer 1

1

Use array for name of checkboxes name="banks[]"

<input
                        id="bank_{{$item['code']}}"
                        name="banks[]"
                        class="form-check-input bank"
                        type="checkbox"
                        value="{{$item['code']}}"
                        checked/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.