I want to pass php variable to javascript variable. When i click on error, it gives a redline under "console.log(data)" But it throws the error in Console Window -
Uncaught SyntaxError: Unexpected identifier
I am new to Javascript.
Javascript:
<script>
$('#clientName').on('change', function() {
var clientname = $(this).val();
var clientid = $('#clients-list option[value=' + clientname +']').attr('id');
var data = [];
data = <?= $client_data ?>
console.log(data);
});
</script>
PHP Variable ( $client_data ) :
Array
(
[0] => Array
(
[id] => 1
[client_name] => John Doe
[client_shop_street] => Baker Street
[client_city_town] => California
[client_pincode] =>
[client_desc] => hello1
[client_contact1] => 1234567890
[client_contact2] => 1111111111
[client_email] =>
[client_total_amt] => 45000
[client_paid_amt] => 37000
[created_at] =>
[updated_at] => 2021-06-21 18:39:54
[created_by] => 1
)
[1] => Array
(
[id] => 2
[client_name] => Tom Jerry
[client_shop_street] => Wall Street
[client_city_town] => New York
[client_pincode] =>
[client_desc] => testing demo
[client_contact1] => 2222222222
[client_contact2] => 3333333333
[client_email] =>
[client_total_amt] => 45000
[client_paid_amt] => 37000
[created_at] =>
[updated_at] => 2021-06-21 23:32:12
[created_by] => 1
)
)