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

251
Views
Passing php variable to js script in blade function

js functions in the script provided at the end of the blade should show/hide div with specific id according to the sent one in the parameter but looks like js functions don't receive php parameters from blade as the div blades are given different ids as intended but they can't be accessed from the js functions. My question is how to use functions on specific div (notice that div are created by a foreach loop with different ids)

@foreach($postsList as $post)
<div id="post_div_{{$id}}" style="font-weight:bold" class="p-6 bg-white border-b border-gray-200">

    @php
    $id=$post->id;
    @endphp

    <strong>{{$post->title}}</strong>
    <a>Added: {{$post->created_at}}</a>

    <form method="POST" action="/posts/delete/{{$post->id}}">
        <button id="DeleteButton" onclick="deletePost($id)" type="button">Delete</button>
    </form>

    <button onclick="editPost($id)" type="button">Edit</button>
    <div id="all_div_{{$id}}" class="p-6 bg-white border-b border-gray-200" style="display: none;">@include('editPost', ['post'=>$post])</div>

    <script type="text/javascript">
        function deletePost($id) {
            document.getElementById('post_div_' + {
                $id
            }).style.display = "none";
        }

        function editPost($id) {
            document.getElementById('all_div_' + {
                $id
            }).style.display = "block";
        }
    </script>
</div>
@endforeach
about 4 years ago · Juan Pablo Isaza
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!