Bonjour tout le monde,
Cette fonction PHP me permet de transformer un tableau PHP en un tableau javascript (cela peut être utile pour quelqu'un d'autre) :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| <?php
//IMPORTANT : php génere un script js
//transforme un tableau php en un tableau javascript !!!
//type => soit TH soit TP, je ne dois pas écrire deux fonctions comme cela, il choisit la fonction par rapport au type
function construisTableauJS($tableauPHP,$type)
{
echo $type;
if(type == "TH")
{
echo'<script langage="javascript">';
$tab_cotes_TH_js = "tab_cotes_TH_js";
echo $tab_cotes_TH_js." = new Array();";
for($i = 0; $i < count($tableauPHP); $i++)
{
if(!is_array($tableauPHP[$i]))
{
echo $tab_cotes_TH_js.'.push("'.$tableauPHP[$i].'");';
}
}
echo'</script>';
return;
}
else
{
echo $type;
echo'<script langage="javascript">';
$tab_cotes_TP_js = "tab_cotes_TP_js";
echo $tab_cotes_TP_js." = new Array();";
for($i = 0; $i < count($tableauPHP); $i++)
{
if(!is_array($tableauPHP[$i]))
{
echo $tab_cotes_TP_js.'.push("'.$tableauPHP[$i].'");';
}
}
echo'</script>';
return;
}
}
?> |
j'appelle donc la fonction comme ceci :
construisTableauJS($cotes_TH, "TH");
Je lui passe donc "TH" ou "TP" afin qu'il sache ce qu'il doit faire.
Firebug me donne sans cesse ce message d'erreur :
<body bgcolor="#F4FFE4" onload="calculs(tab_cotes_TH_js,tab_cotes_TP_js);">
Car j'essaie d'envoyer mes tableaux à une fonction javascript que voici :
1 2 3 4 5
| function calculs(tableau_cotes_th,tableau_cotes_tp)
{
alert("ici");
alert(tableau_cotes_th,tableau_cotes_tp);
... |
L'alerte ne se lance pas (ici), je n'arrive donc pas là.
Sauriez-vous me dire ce que je peux faire pour résoudre ce problème svp ?
Un tout grand merci d'avance.
beegees
Partager