Now follows the function; what I need is to simply pass the value of a variable within JavaScript to PHP, if I make a single code without so many quotes and call works, but when I mix everything goes problem, I think it's two things
1-something related to tag closing < script > 2-start and end of quotation marks.
The problem lies in this blessed line
table $="< script > document.write (varTB) < / script >"
If I put the SQL string in hand, it works good ... but when I try to write well does not work. What can it be?
Give me strength, I'm crawling in the web world. grateful
<button name="addEnvolvido" onclick="carregaCombo('tipolocal','idocorrencia')">Adicionar</button><br/>
<select id="idocorrencia">
<option value=""></option>
</select>
<?php include("conexao.php"); ?>
<script type="text/javascript">
function carregaCombo(nomeTB, nomeCombo)
{
select = document.getElementById(nomeCombo);
var varTeste = '';
var varTB = nomeTB;
varTeste =
<?php
//echo '"item 1"';
$tabela = "<script>document.write(varTB)</script>";
$varResult = '"';
$result = mysqli_query($con, 'SELECT id, nome FROM ' . $tabela);
//nomeTB ORDER BY nome');
while($row = mysqli_fetch_array($result))
{
$varResult .= $row[0] . '-' . $row[1] . ';';
}
//remove o ultimo ; da variavel
$varResult = substr($varResult,0,-1);
$varResult .= '"';
echo $varResult;
?>;
//agora separar o ID do nome
for (var i = 0; i < varTeste.split(";").length ; i++)
{
var opt = document.createElement('option');
opt.value = varTeste.split(";")[i];
opt.innerHTML = varTeste.split(";")[i];
select.appendChild(opt);
}
}