Bonjour,
Cela fait plusieurs fois que je tombe sur ce problème et j'aimerais trouver ne serait-ce qu'une explication.
Le contexte : Sur une page que j'aimerais gérer sans rechargement, j'utilise une fonction JS qui utilise jquerry pour rajouter un SELECT avec ses lignes OPTION qui sont issus d'une base de donnée. Jusque la tout marche bien. Maintenant dans ces éléments OPTION, j'ai un attribut onclick qui est censé appeler une fonction. Seulement dans les fait cette fonction n'est jamais lancée. Quand j'utilise l'examinateur de code, déjà, le onclick n'apparait pas. En regardant avec firebug, l'attribut apparait mais ne semble pas fonctionner.
J'ai lu quelque part que l'ajout de déclencheur en "texte" ne fonctionne pas si celui ci n'était pas présent sur la page au moment de sa génération (donc dans mon cas, puisqu'il est ajouté par du jquerry, c'est en effet la situation dans laquelle je suis.
Seulement je trouve cela très embettant, je n'ai pas réussi a trouvé de solution sur le net, ni même auprès de mes professeurs. Quelqu'un d'autre a t-il déjà eu a faire avec ce problème ?
Merci !
EDIT :
Voici le code si cela vous aide davantage, c'est donc la fonction hideothername et showothername qui ne sont pas prise en compte après modification :
mon script js :
affichermenu.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
42 function hideothername(nature) { var nom_bloc_id = "othernamelot"; if(nature == '1') $(nom_bloc_id).removeClass().addClass("hidden"); else { nom_bloc_id += String(nature); $(nom_bloc_id).removeClass().addClass("hidden"); } console.log("lol"); } function addothername(nature) { var nom_bloc_id = "othernamelot"; if(nature == '1') $(nom_bloc_id).removeClass().addClass("inline"); else { nom_bloc_id += String(nature); $(nom_bloc_id).removeClass().addClass("inline"); } console.log("lol"); } function aff_menu(nomtype){ if(nomtype == "lot"){ $.post("affichermenu.php", { nomtype: "lot" }, function(data){ $("#typenature").empty().append( data ); }); } if(nomtype == "bon"){ $.post("affichermenu.php", { nomtype: "bon" }, function(data){ $("#typenatur2").empty().append( data ); }); } if(nomtype == "complement"){ $.post("affichermenu.php", { nomtype: "complement" }, function(data){ $("#typenatur3").empty().append( data ); }); } if(nomtype == "info"){ $.post("affichermenu.php", { nomtype: "info" }, function(data){ $("#typenatur4").empty().append( data ); }); } }
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?php $nomtype1 = $_POST['nomtype']; $bdd = mysqli_connect(); $nomtype = mysqli_real_escape_string($bdd, $nomtype1); $database = "nom".$nomtype."s"; $datafield = "nom".$nomtype; $req = mysqli_query($bdd, "SELECT * FROM $database ORDER BY $datafield"); $rep = ""; if($nomtype == "lot"){ while($don = mysqli_fetch_array($req)) { $rep.="<OPTION onclick=\"hideothername('1');return false;\">".$don["$datafield"]."</OPTION>"; } $rep.="<OPTION onclick=\"addothername('1');return false;\">Autre nom</OPTION>"; } if($nomtype == "bon"){ while($don = mysqli_fetch_array($req)) { $rep.="<OPTION onclick=\"hideothername('2');return false;\">".$don["$datafield"]."</OPTION>"; } $rep.="<OPTION onclick=\"addothername('2');return false;\">Autre nom</OPTION>"; } if($nomtype == "complement"){ while($don = mysqli_fetch_array($req)) { $rep.="<OPTION onclick=\"hideothername('4');return false;\">".$don["$datafield"]."</OPTION>"; } $rep.="<OPTION onclick=\"addothername('4');return false;\">Autre nom</OPTION>"; } if($nomtype == "info"){ while($don = mysqli_fetch_array($req)) { $rep.="<OPTION onclick=\"hideothername('3');return false;\">".$don["$datafield"]."</OPTION>"; } $rep.="<OPTION onclick=\"addothername('3');return false;\">Autre nom</OPTION>"; } mysqli_close($bdd); echo $rep; ?>
Partager