How to put this JS variable into PHP variable? [duplicate] - javascript

This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 8 years ago.
I would like to know how to make use of the variable hash in a PHP variable
var hash = md5(a);

Here is the equivalent in PHP:
$hash = md5($a);

Related

How do I pass variables and data from JavaScript to PHP? [duplicate]

This question already has answers here:
How do I edit PHP variable with JavaScript/jQuery?
(2 answers)
jQuery Ajax POST example with PHP
(17 answers)
Closed 2 years ago.
How do I pass variables and data from JavaScript to PHP?
like this:
var client_code = $('#client_code').val();
$client_code = client_code;
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

how to put javascript variable in php array [duplicate]

This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
How do I pass JavaScript variables to PHP?
(16 answers)
Closed 4 years ago.
I need to add JavaScript variable to PHP array, my code is below and var date1 is JavaScript variable.
Code
$date1="2018-08-02";
$date=explode("-",$date1);
My JavaSript section is here
var date1=new Date(<?=$date[0].",".$date[1].",".$date[2]?>);
date1 place to index of array x
$incoming[$i] = array("x" =>+date1 , "y" => $total_inc);
$outgoing[$i] = array("x" => +date1, "y" => $total_out);
In this situation the value is return 0.
You can't. JS code is executed after PHP finished executing own code. You can pass data from js to php by ajax or by setting a cookie.

Calling Javascript variable inside javascript code [duplicate]

This question already has answers here:
How can I do string interpolation in JavaScript?
(21 answers)
Closed 6 years ago.
I have the following code
dt.ajax.url( 'test.php?status=' ).load();
I defined a variable
var status= 55
I wand to add status_2 in the link like this
dt.ajax.url( 'test.php?status=&status' ).load();
How can I do it ?
Try this. You need to concatenate the variable with url
dt.ajax.url('test.php?status='+status).load();

Calling a javascript function while coding in PHP [duplicate]

This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 7 years ago.
I am trying to get a variable from my javascript function while I'm coding in PHP.
my javascript which is included in the page:
function subAmt(empid, subid){
return 4;
}
my attempt to call that function:
$amt = echo "subAmt(3,5);" ;
You need the script tags I think?
echo '<script type="text/javascript">'
, 'subAmt(3,5);'
, '</script>'
;
Please refer to this question:
How to call a JavaScript function from PHP?

Get Yii user state variables in javascript [duplicate]

This question already has answers here:
In Yii, pass PHP variables to JavaScript
(6 answers)
Closed 8 years ago.
I am using Yii::app()->user->setState to set some user's session variables.
Is there a way to get the values of them from within JavaScript?
Something like this perhaps? You have to echo it to the JavaScript.
<script>
var myVariable = "<?= Yii::app()->user->getState('myVariable', '') ?>";
alert(myVariable);
</script>

Categories