Emy
Emy

Reputation: 89

Select2 - There is no selected value in the selection field after clicking the submit button

i have the problem with my select. When i select option and click on submit button the selected value is lost.

 {{ Form::open(['url' => route('index'), 'method' => 'GET', 'class' => 'form']) }}
                {{ csrf_field() }}
<select class="form-control select2" data-tags="true" data-placeholder="Select filter" data-allow-clear="true" name="filterClients" id="filterClientBy" style="width: 100%;">
<option></option>
<option name="firstCalling" value="firstCalling" {{Request::has('firstCalling')?'selected':''}}>First callin</option>
<option name="firstVisit" value="firstVisit"{{Request::has('firstVisit')?'selected':''}}>First visit</option>
</select>
<button type="submit" id="apply" class="btn btn-success">Apply filters</button>
  {{ Form::close() }}
This code is only part of my code... After submit there is not a value. How to solve that? enter image description here`

Upvotes: 0

Views: 505

Answers (2)

brk
brk

Reputation: 50326

form submit is a kind of page refresh. Try to submit the form using an ajax request

<form onsubmit="yourFunctionName()"> 
// rest of the form
</form>

function yourFunctionName(e){
    event.preventDefault();
    //here ajax code to submit the form value
  }

Upvotes: 0

Bram Houben
Bram Houben

Reputation: 180

instead of <form> use <form action="name of file or #" method="post or get ">

Upvotes: 2

Related Questions