-2

How do I pass variables and data from JavaScript to PHP? like this:

var client_code = $('#client_code').val();

$client_code = client_code; 
  • Look into AJAX. – devlin carnate Jul 24 '20 at 20:29
  • Why do you want to? You want to send a client side value to the server side but for what purpose? I ask to make sure what you intend to do is what you need to do. – TimBrownlaw Jul 24 '20 at 20:29
  • 1
    You won't do it directly, you need to send a request to a PHP script, you can use an AJAX as already mentioned in the previous comments, or ie. by filling and submitting HTML form. – biesior Jul 24 '20 at 20:31
  • Describe your problem better, JavaScript is a client-side technology, and PHP is server-side, which means, that your PHP script is ALWAYS executed after some action in the frontend (client-side). How do you want to use JS' `client_code` value as your PHP's `$client_code` variable in the future? Describe it best you can, to let us understand your problem. – biesior Jul 24 '20 at 20:45

1 Answers1

-1

You can't pass data from JS to PHP directly. But you can use AJAX functions to pass the data as asynchronous.

You can read from https://www.w3schools.com/jquery/jquery_ref_ajax.asp

Jakadar
  • 1
  • 2