Bisogna sapere che non è possibile usare del php .... in js.
Quindi non puoi scrivere una funzione js con delle variabili php.
E' un po' difficile capire quello che fai, ma forse con un esempio diverso capirai quello che voglio dire. Guarda poi il sorgente generato dai 2 esempi (che fanno la stessa cosa sostenzialmente).
Esempio 1 :
codice:
<?php
$arrPaziente[] = "Marco";
$arrPaziente[] = "Giulio";
$arrPaziente[] = "Franco";
$arrPaziente[] = "Andrea";
$arrPaziente[] = "Gerardo";
$arrPaziente[] = "Alessio";
$arrPaziente[] = "Ercole";
$arrPaziente[] = "Mirko";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
function example(paziente) {
alert('Ciao ' + paziente);
return false;
} // function example(paziente)
//-->
</script>
</head>
<body>
<?php
//----------- Creazione
foreach($arrPaziente as $paziente) {?>
');"> Elimina <?php print $paziente ?>
<?php
} // foreach($arrPaziente as $paziente) ?>
</body>
</html>
Esempio 2 :
codice:
<?php
$arrPaziente[] = "Marco";
$arrPaziente[] = "Giulio";
$arrPaziente[] = "Franco";
$arrPaziente[] = "Andrea";
$arrPaziente[] = "Gerardo";
$arrPaziente[] = "Alessio";
$arrPaziente[] = "Ercole";
$arrPaziente[] = "Mirko";
$javascript = "";
$html = "";
foreach($arrPaziente as $paziente) {
//--------- Creo una funzione per paziente
$pippo = "function example_$paziente() {\n";
$pippo .= "alert('Ciao $paziente');\n";
$pippo .= "} // function example_$paziente() {\n";
$javascript .= $pippo;
//-------- Creo il tag a per paziente
$pippo = "<a href=\"javascript:void(0)\" onclick=\"example_$paziente();\"> Elimina $paziente</a>
\n";
$html .= $pippo;
} // foreach($arrPaziente as $paziente)
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
<?php print $javascript ?>
//-->
</script>
</head>
<body>
<?php print $html ?>
</body>
</html>