Hassan
Hassan

Reputation: 422

How can I pass data submit form with jquery

I am working on laravel project and I try to pass color code to conroller for doing some stuff but I could not pass data of data att for a tag

I want to send it with url some thing like this :

http://localhost:8000/digikala/category/28?minprice=+1000+&maxprice=+100000000+&type=all&color=FFFFFF&sortBy%5Bfield%5D=created_at%7Cdesc

but it does not give me color and it is like this

http://localhost:8000/digikala/category/28?minprice=+1000+&maxprice=+100000000+&type=all&sortBy%5Bfield%5D=created_at%7Cdesc

here is my a tag :

<a class="options-color" data-color="{{ $color->code }}" style="background-color:#{{ $color->code }}">

here is my js :

<script>
$(document).ready(function() {
    $(".options-color").click(function() {
        var color = $(this).data('color');
        $('#submit').trigger('submit', color);

    });
});

Upvotes: 1

Views: 625

Answers (1)

TsaiKoga
TsaiKoga

Reputation: 13404

add color hidden input in your html:

<input id='color-input' type='hidden' name='color' value=''/>
$(".options-color").click(function(e) {
  e.preventDefault();

  var color = $(this).data('color');
  $("#color-input").val(color);
  $('#submit').trigger('submit');
}

Upvotes: 1

Related Questions