I want first to execute form and after that onClick(function) because the post form doesn't work.In this form if green button is submitted ,shows red button. After button is submitted I want to print hidden div. Thank you !
blade
@foreach($movie->seats as $seat)
<div id="printDiv" style="display:none;text-align:center">
<h3 >Ред: 4</h3>
<h3>Място: {{$seat->seat_id}}</h3>
<h3>Филм: {{$movie->title}}<h3>
<h3>Час: {{$movie->hour}}</h3>
</div>
@if($seat->reserved == 0)
<form id="data" method="post" action="/seat/{{$seat->id}}">
@csrf
<button type="submit" onclick="printDiv('printDiv')" style="margin-left:10px; width:80px; display:inline;" type="button" class="btn btn-success">{{$seat->seat_id}}</button>
</form>
@else
<form method="post" action="/destroy/{{$seat->id}}">
@csrf
<button type="submit"style="margin-left:10px; width:80px; display:inline;" type="button" class="btn btn-danger">{{$seat->seat_id}}</button>
</form>
@endif
@endforeach
Script
function printDiv($idPage){
var printContents = document.getElementById($idPage).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
};
Controller
public function changeReserved($id,Request $request){
$request = Seats::find($id);
$request->reserved = '1';
$request->save();
return redirect()->back();
}