Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

286
Views
How to execute form and after that onClick in Laravel

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();

        
    }
about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!