Is there any way to pass a javascript variable to a php function or simply assign a js variable to a php variable....???
test(\"asdas\"); I need to update \"asdas\" to a
You can pass value from js to PHP using ajax request or add js value to URL and then reload page.
Variant #1 (using ajax):
JS side (jquery)
var js_var = 'hello';
$.ajax({
type: "POST",
url: "some.php",
data: "js_var="+js_var,
success: function(msg){
alert( "Data Saved: " + msg );
}
});
PHP side
$js_var = isset($_POST['js_var']) ? $_POST['js_var'] : '';
Variant #2 (with page reload):
JS side
PHP side
$js_var = isset($_GET['js_var']) ? $_GET['js_var'] : '';