I am getting error when I use some code inside a JavaScript file, but inserting into HTML div. I used a PHP method to show all clients, and is working fine in html page. But in JavaScript I get error in the echo.
See error in Visual Studio Code ==> https://prnt.sc/1yy4sxl
Here is my code:
$(this).parent().parent().parent().children(".clientNewOrder").html(
'<div class="form-group">' +
' <div class="input-group mb-3">' +
' <div class="input-group-prepend">' +
' <select class="form-control" required>' +
' <option value="">Select Client</option>' +
' <?php' +
' $item = null;' +
' $valor = null;' +
' $selectClient = ControllerClients::ctrReadClients($item, $values);' +
' foreach ($selectClient as $key => $value) {' +
' echo <option value=".$value["id"]. ">'.$value["name"]. '</option>;' +
' }' +
' ?>' +
' </select>' +
' </div>' +
' </div>' +
'</div>'
)
I tried changing "" '' but problem still here. I removed '' in echo ' ', something like this:
' echo <option selected>Select</option>' +
' <option value="01">John</option>' +
' <option value="02">Mary</option>;' +
and is running ok in this manual form, but dynamically I can't handle it