0

Inside a toolbar.blade I have this:

<script>
$('.form-control').on('change',function(){
var TourDate = document.getElementById('TourDate').value;
if($('#TourDate_hidden').val()=="" || $('#TourID').val()==""){
    return;
  }
keyword= '_kfdTourDate:equal:'+$('#TourDate_hidden').val()+'|';
keyword+= '_kfnTourID:equal:'+$('#TourID').val();

reloadData( '#{{ $pageModule }}',"{{ $pageUrl }}/data?search="+keyword);    
console.log(TourDate);
});
</script>

Also I have a text input and a selectbox in toolbar.blade. the input and selectbox look like this:

    <input type="text" class="form-control" name="TourDate" 
id="TourDate" data-value="{{$testdate}}">

@if(count($tourTypes))
  <select name="_kfdTourID" id="TourID" onkeyup='saveValue(this);'>
    @foreach($tourTypes as $tourType)
      <optgroup label="{{ $tourType->_kftDescription }}">
          @if(count($tourType->tours))
          @foreach($tourType->tours as $tour)
          <option value="{{ $tour->_kpnID }}">{{ $tour->tDescription }}</option>
          @endforeach
          @endif
      </optgroup>
    @endforeach
  </select>
@endif

When I click on text input, a boostrap calendar is poping up, after selecting a date it's showing the selected date inside the input and the page is reloading with the new filtered data trough ajax

e.g. XHR finished loading: GET "http://www.website.com/bookings/data?search=_kfdTourDate:equal:2017-03-11|_kfnTourID:equal:4

After the page is reloaded trough ajax the value inside the input is becoming empty and the first option in the selectbox is being selected automatically.

When I write

@php
        $testdate = "16/03/2017";
@endphp

above the input I can see the date 16/03/2017 inside the input. Also I can print the selected tour date using console.log(TourDate) Even after I refresh the page the date 16/03/2017 stays inside the input. But somehow I cannot assign jquery variable TourDate to php variable testdate. How can I keep the data-value for the input and mark the selected option as selected after the page is refreshed?

I tried this: keep input value after refresh page but couldn't make it work. I tried almost everything the whole day. I desperately need help to make this work. Thanks in advance for help.

Community
  • 1
  • 1
Johnny
  • 1,685
  • 6
  • 24
  • 42
  • client side information can be send to the server with a http call: e.g. `GET` or `POST`. You can do this using `xhr` (`ajax`) in order to not reload the page entirely. https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Sending_and_retrieving_form_data – online Thomas Mar 16 '17 at 14:54
  • `$testdate = $_GET('TourDate')` didn't work nor `$testdate = "";` – Johnny Mar 16 '17 at 15:04
  • you might have to use the laravel way: `$request->input('TourDate');` – online Thomas Mar 16 '17 at 15:08
  • I get the error `undefined variable: request ` – Johnny Mar 16 '17 at 15:10
  • I'm sorry but you have clearly not read the documentation: https://laravel.com/docs/5.4/requests – online Thomas Mar 16 '17 at 15:11
  • So, I need to create `public function store(Request $request)` and `public function update(Request $request)` ? – Johnny Mar 16 '17 at 15:18
  • It depends: the route declared in routes/web.php or routes/api.php determine which request goes to which function. The example you mention is for a resource controller. – online Thomas Mar 16 '17 at 15:20

1 Answers1

0

using document.write() you can assign a javascript variable value inside the php variable as

$phpVariable = "<script>document.write(javascriptVariable);</script>";
RAUSHAN KUMAR
  • 5,846
  • 4
  • 34
  • 70