j'ai creé un tableau et je souhaite le remplir grace a des variables.
(il s'agit d'un tableau de score réalisé par l'utilisateur dans differents exercices)
Quand je met une variable en dur genre var test = "blabla"; et que je veux afficher la variable tout va bien.
Le probleme c'est que je veux afficher une variable qui est le résultat d'une fonction et la, a chaque fois, il me dit "undefined".
C'est a mon avis un probleme de variable locale/globale mais je n'arrive pas a le resoudre.
Voici comment j'affiche mon tableau:
Dans ma page score.html j'ai ces cette ligne:
[CODE]<br> <div id="support1" class="support1"><SCRIPT language="javascript">document.write(eval(idfiche+"tableaus_lire")); </SCRIPT>/CODE
Et dans variables.js j'ai mon tableau:
[CODE]var score_tableaus_lire = "Pour les exercices : 'Savoir lire' <br><br><TABLE BORDER=1 BORDERCOLOR=#000000 CELLPADDING=5 CELLSPACING=0> <TR VALIGN=TOP> <TD class='texte'> Exercice </TD> <TD ><NOBR><span class='texte'> Bonnes réponses </span> </TD> <TD ><span class='texte'> Érreures </TD> </TR> <TR VALIGN=TOP><td><span class='texte'> I. Je lis, j'entends, j'écris </TD> <TD ><NOBR> </TD> <TD > "+score_titre+" </TD> </TR> <TR VALIGN=TOP><td><span class='texte'> II. Je retrouve l'ordre alphabétique </TD> <TD ><NOBR><span class='texte'> </TD> <TD ><span class='texte'> </TD> <TR VALIGN=TOP><td><span class='texte'> III. Je sais ponctuer et mettre en page un texte </TD> <TD ><NOBR><span class='texte'> </TD> <TD ><span class='texte'> </TD> </TR><TR VALIGN=TOP><td><span class='texte'> IV. Je sais identifier un texte ou un type de document </TD> <TD ><NOBR><span class='texte'> </TD> <TD ><span class='texte'> </TD> </TR><TR VALIGN=TOP><td><span class='texte'> V. Je sais retrouver des informations dans un tableau </TD> <TD ><NOBR><span class='texte'> </TD> <TD ><span class='texte'> </TD> </TR><TR VALIGN=TOP><td><span class='texte'> VI. Je comprends ce que je lis </TD> <TD ><NOBR><span class='texte'> </TD> <TD ><span class='texte'> </TD> </TR><TR VALIGN=TOP><td><span class='texte'> VII. Je comprends ce que dit le texte </TD> <TD ><NOBR><span class='texte'> </TD> <TD ><span class='texte'> </TD> </TR><TR VALIGN=TOP><td><span class='texte'> VIII. J'évalue la richesse de mon vocabulaire </TD> <TD ><NOBR><span class='texte'> </TD> <TD ><span class='texte'> </TD> </TR><TR VALIGN=TOP><td><span class='texte'> IX. Je sais reconnaître les niveaux de langue </TD> <TD ><NOBR><span class='texte'> </TD> <TD ><span class='texte'> </TD> </TR> </TR> </TR></TABLE><br>"; /CODE
Et enfin, la variable que je veux afficher c'est
scoreexosl_1_enonce1 qui est dans la page fonction.js
[CODE]function correctionsl_1_enonce1()
{
var scoreexosl_1_enonce1 = 0;
var difscoreexosl_1_enonce1 = 0;
// case 1
var en1 = document.getElementById("sl_1_enonce1_1").value;
var rep1 = document.getElementById("sl_1_sol1_1").value;
if(en1 == rep1)
{
document.getElementById("sl_1_enonce1_1").style.backgroundColor='green';
scoreexosl_1_enonce1 = scoreexosl_1_enonce1 +1;
}
else document.getElementById("sl_1_enonce1_1").style.backgroundColor='red';
//alert("Correct ");
//if(en1 != rep1)
//alert("inCorrect ");
// case 2
var en2 = document.getElementById("sl_1_enonce1_2").value;
var rep2 = document.getElementById("sl_1_sol1_2").value;
if(en2 == rep2)
{
document.getElementById("sl_1_enonce1_2").style.backgroundColor='green';
scoreexosl_1_enonce1 = scoreexosl_1_enonce1 +1;
}
else document.getElementById("sl_1_enonce1_2").style.backgroundColor='red';
//alert("Correct ");
//if(en2 != rep2)
//alert("inCorrect ");
// case 3
var en3 = document.getElementById("sl_1_enonce1_3").value;
var rep3 = document.getElementById("sl_1_sol1_3").value;
if(en3 == rep3)
{
document.getElementById("sl_1_enonce1_3").style.backgroundColor='green';
scoreexosl_1_enonce1 = scoreexosl_1_enonce1 +1;
}
else document.getElementById("sl_1_enonce1_3").style.backgroundColor='red';
//alert("Correct ");
//if(en3 != rep3)
//alert("inCorrect ");
// case 4
var en4 = document.getElementById("sl_1_enonce1_4").value;
var rep4 = document.getElementById("sl_1_sol1_4").value;
if(en4 == rep4)
{
document.getElementById("sl_1_enonce1_4").style.backgroundColor='green';
scoreexosl_1_enonce1 = scoreexosl_1_enonce1 +1;
}
else document.getElementById("sl_1_enonce1_4").style.backgroundColor='red';
//alert("Correct ");
//if(en4 != rep4)
//alert("inCorrect ");
// case 5
var en5 = document.getElementById("sl_1_enonce1_5").value;
var rep5 = document.getElementById("sl_1_sol1_5").value;
if(en5 == rep5)
{
document.getElementById("sl_1_enonce1_5").style.backgroundColor='green';
scoreexosl_1_enonce1 = scoreexosl_1_enonce1 +1;
}
else document.getElementById("sl_1_enonce1_5").style.backgroundColor='red';
//alert("Correct ");
//if(en5 != rep5)
//alert("inCorrect ");
difscoreexosl_1_enonce1 = 5 - scoreexosl_1_enonce1;
alert("Ton score est de : "+scoreexosl_1_enonce1+"/5. Tu as donc fait : "+difscoreexosl_1_enonce1+" érreures.");
return scoreexosl_1_enonce1;
//alert("le champ a pour valeur : "+scoreexo);
// alert("le champ a pour valeur : "+obj1);
// alert("le champ a pour valeur : "+obj2);
//self.location.href="index.html?scoreexosl_1_enonce1="+scoreexosl_1_enonce1;
}/CODE
Et voici fiche_1
<HTML>
<HEAD>
<TITLE>CRDP de L'académie de Nice -- Accompagenement scolaire
</TITLE>
<link href="../crdp.css" rel="stylesheet" type="text/css">
<SCRIPT LANGUAGE="JavaScript" SRC="../variables.js"></script>
<SCRIPT LANGUAGE="JavaScript" SRC="../fonctions.js"></script>
<SCRIPT LANGUAGE="JavaScript">
var idfiche="sl_1_";
//alert(eval(idfiche+"support");
</script>
<script type="text/javascript" language="javascript" src="../test/lytebox.js"></script>
<link rel="stylesheet" href="../test/lytebox.css" type="text/css" media="screen" />
</HEAD>
<body id="idfiche" class="fiche" onload="initialisation(idfiche); cache('consigne');" onMouseOver="affmenulateral();" >
<table class="tbl-test" cellspacing="0" cellpadding="0">
<tr>
<td class="cell1">
<!--menu onglet-->
<div id="onglet">
<div class="onglet" id="active">
<a href="#1" onClick="affiche('activite1');cache('activite2');cache('activite3');cache('consigne');cachesol();">Niveau 1</a>
</div>
<div class="onglet" >
<a href="#2" onClick="cache('activite1');affiche('activite2');cache('activite3');cache('consigne');cachesol();">Niveau 2</a>
</div>
<div class="onglet" >
<a href="#3" onClick="cache('activite1');cache('activite2');affiche('activite3');cache('consigne');cachesol();">Niveau 3</a>
</div>
<div class="onglet" >
<a href="#3" onClick="cache('activite1');cache('activite2');cache('activite3');affiche('consigne');cachesol();">A revoir</a>
</div>
</div>
<br>
</td>
</tr>
<tr>
<td class="cell2">
<div class="inter">
<div id="activite1" >
<table>
<tr >
<td class="support"><SCRIPT language="javascript">document.write(eval(idfiche+"support1")); </SCRIPT>
</td>
<td class="divact">
<span class="niveau">NIVEAU 1
</span>
<br>
<span class="titre_activite">Activité :</span>
<span class="activite">
<SCRIPT language="javascript">document.write(eval(idfiche+"enonce1")); </SCRIPT><br />
<!-- benjamin <SCRIPT language="javascript">document.write(eval(idfiche+"enonce1_1")); </SCRIPT><br /> -->
</span>
<div align=center>
<SCRIPT language="javascript">document.write(eval("corrigeloupsavant")); </SCRIPT><br />
<a href="#[1]" onclick=correctionsl_1_enonce1() >
<img src="../images/fleche_jaune.gif" alt="Regarde la réponse" width="105" height="55" /></a> </A>
<br><br>
<SCRIPT language="javascript">document.write(eval("reponseloupsavant")); </SCRIPT><br />
<a href="#[1]" onclick=reponse_1_enonce1() >
<img src="../images/fleche_jaune.gif" alt="Regarde la réponse" width="105" height="55" /></a> </A>
</div>
<!-- <a href="#[1]" onclick="display('sol_1');">
<img src="../images/fleche_jaune.gif" alt="Regarde la réponse" width="105" height="55" /></a> </A> -->
<!-- <input type="button" name="Submit" onclick="document.location.replace('../score.php')"> -->
<!-- <a href="#[1]" onclick="document.location.replace('../score.php');Montrer(sl_1_document);display('sol_1');">
<img src="../images/fleche_jaune.gif" alt="Regarde la réponse" width="105" height="55" /></a> </A> -->
<!-- <input type=button value=" Alert" onClick="drawAlert()"> -->
<div id='sol_1'class='solution' >
<br />
<span id='sol_1' class="solution_txt">
<SCRIPT language="javascript">document.write(eval(idfiche+"sol1"));</SCRIPT><br />
</span>
</div>
</td>
</tr>
</table>
</div>
<div id="activite2" >
<table>
<tr >
<td class="support">
<SCRIPT language="javascript">document.write(eval(idfiche+"support2")); </SCRIPT>
</td>
<td class="divact">
<span class="niveau">NIVEAU 2
</span>
<br>
<span class="titre_activite">Activité :</span>
<span class="activite">
<SCRIPT language="javascript">document.write(eval(idfiche+"enonce2")); </SCRIPT><br />
</span>
<a href="#[1]" onclick="display('sol_2');">
<img src="../images/fleche_jaune.gif" alt="Regarde la réponse" width="105" height="55" /></a> </A>
<div id='sol_2'class='solution' >
<span class="solution_txt">
<SCRIPT language="javascript">document.write(eval(idfiche+"sol2")); </SCRIPT><br />
</span>
</div>
</td>
</tr>
</table>
</div>
<div id="activite3" >
<table>
<tr >
<td class="divact">
<span class="niveau">NIVEAU 3</span>
<br>
<span class="titre_activite">Activité :</span>
<span class="activite"> <SCRIPT language="javascript">document.write(eval(idfiche+"enonce3")); </SCRIPT><br /></span>
<br> <a href="#[1]" onclick="display('sol_3');"> <img src="../images/fleche_jaune.gif" alt="Regarde la réponse" width="105" height="55" /></a>
</A>
<br>
<div id='sol_3'class='solution' >
<span class="titre_activite">Corrigé de la lettre :<br></span><br>
<span class="solution_txt"> <SCRIPT language="javascript">document.write(eval(idfiche+"sol3")); </SCRIPT><br /></span>
</div>
</td>
</tr>
</table>
</div>
</div>
<div id="consigne" class='consigne'>
<br><br><br><SCRIPT language="javascript">document.write(eval(idfiche+"consigne")); </SCRIPT></div>
</td>
</tr>
</table>
</div>
</body>
</html>
VOici comment ça marche:
Quand je suis sur index, je clique sur un lien qui m'amene a fiche 1.
Fiche 1 est un exercice et en bas il y a 2 liens.
Un quicorrige l'exercice en appelant correctionsl_1_enonce1() et un qui affiche les reponses.
Et le but est de remplir le tableau de score.
Si vous pouviez me donner une piste pour me debloquer,
Merci,
Benjamin
