I am trying to pass a php variable to JavaScript that hold the name of the table, data will be written in. However I can not see the value when I console.log it. The script is activate on click, so it should not be an issue with page load, but I am not very good with JavaScript, so I have no idea what I am doing wrong
global $user;
$user = user_load($user->uid);
$params = Array (
'company' => $user->field_active_company[LANGUAGE_NONE][0]['value'] ,
);
$id = $user->name;
$cu = "db_".$params['company'];
//Here I can see the value fine
echo $cu;
.
.
.
.
//here I can not.
var write = '<?php echo json_encode($cu); ?>';
console.log(write);
var write2 = '<?php echo $cu; ?>';
console.log(write2);
Edit
To clarify:
- I am asking why it does not work (or how to fix it).
- the JavaScript has a function around it and all the needed tags. I am console logging textboxes prior to the JavaScript/PHP part.
var_dump($cu)
orprint_r($cu)
?