0

I have modal blade page , which loaded by controller which called via ajax.I have a hidden input field.I get the value from input field via javascript dom. I stored in a js variable.The variable works good. I want this value in php variable on same page, for some checking purpose.

Here my code is ....

<script>
    var invoice_no = document.getElementById('invoice_no').value;
</script>

@php

$invoice_no = ;

@endphp

Note : It's a modal (invoiceModal.blade.php)

  • why don't you check in js instead of php? – JS TECH Sep 15 '22 at 08:05
  • 2
    You will have to send it to the server probably using AJAX again and get your reply about its validity from the reply, because of course PHP does not run in the browser – RiggsFolly Sep 15 '22 at 08:06

1 Answers1

0

You will have to send request to the backend for this. The javascript variable cannot be read by your PHP code. Which means there's no way to do this without making a request to the backend.

Main reason:

PHP runs before the Javascript to deliver results to the browser.

Vüsal Hüseynli
  • 889
  • 1
  • 4
  • 16