0

I try to pass two value from javascript to another blade file after click button to redirect to new window ...Here is my code

ReportCreate.blade.php js


 $("#state").on("change", function() {
            var id = $(this).val();
            console.log(id)
            var cuid = document.getElementById("cu").value;  
            console.log(cuid)

        });

    </script>


Click button to open new window which is carry two value from javascript

onclick="openNewWindow('{{ route('sla.slaCategoryTreeListScreen') }}')"

slaCategoryTreeListScreen.blade.php

<!DOCTYPE html>

<script>
// how do i retrieve two value from another blade file
</script>

</html>

1 Answers1

0

First, You'll need to send those values when making the request. You can do this with query params passing a second argument on the route() helper:

onclick="openNewWindow('{{ route('sla.slaCategoryTreeListScreen', ['id' => 123, 'cuid' => 456]) }}')"
                                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Then, you get those values in your controller to finally return them to the second blade file:

# MyCoolController.php

public function toMySecondView(Request $request)
{
    $id = $request->get('id');
    $cuid = $request->get('cuid');

    return view('my_cool_second_view', ['id' => $id, 'cuid' => $cuid]);
}

Just then you'll be able to use them in your second view:

# my_cool_second_view.blade.php

<span> ID: { $id } </span>
<span> CUID: { $cuid } </span>
Kenny Horna
  • 13,485
  • 4
  • 44
  • 71
  • how do i retrieve the id and cuid in javascript method from my second view??? because i want to make ajax from my second view after i get that id and cuid – Adam Fiqrie Putra Feb 04 '20 at 03:34
  • Check this SO answer : https://stackoverflow.com/a/31201101/8388597 You can use json_encode inside handlebar brackets to access data in JS passed to Laravel view – nsg Feb 04 '20 at 04:54