Bonjour,
J'ai utilisé ce tuto http://siddh.developpez.com/articles/ajax/ pour faire une liste liée. Tout fonctionne bien à l'affichage mais j'ai un souci quand j'envoie les valeurs du formulaire dans mon script php qui envoie les emails.
Je n'arrive pas à récupérer la valeur de ma deuxième liste. Je pense qu'il me manque quelque chose sur le bouton d'envoi mais je n'arrive pas à trouver quoi.
Je suis novice en javascript et j'ai déjà passé plusieurs heures à essayer de trouver une solution.
Code du <Header>
Code du <Body>
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
43
44
45
46
47 <script type='text/javascript'> function getXhr(){ var xhr = null; if(window.XMLHttpRequest) // Firefox et autres xhr = new XMLHttpRequest(); else if(window.ActiveXObject){ // Internet Explorer try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } } else { // XMLHttpRequest non supporté par le navigateur alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); xhr = false; } return xhr; } /** * Méthode qui sera appelée sur le click du bouton */ function go(){ var xhr = getXhr(); // On défini ce qu'on va faire quand on aura la réponse xhr.onreadystatechange = function(){ // On ne fait quelque chose que si on a tout reçu et que le serveur est ok if(xhr.readyState == 4 && xhr.status == 200){ leselect = xhr.responseText; // On se sert de innerHTML pour rajouter les options a la liste document.getElementById('ville').innerHTML = leselect; } } // Ici on va voir comment faire du post xhr.open("POST","DeptPays.php",true); // ne pas oublier ça pour le post xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); // ne pas oublier de poster les arguments // ici, l'id de l'auteur sel = document.getElementById('dept'); iddept = sel.options[sel.selectedIndex].value; xhr.send("iddept="+iddept); } </script>
LE code de ma seconde en 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152 <form name="formu" onsubmit="return verifierMail(this.elements['Email']);" action="Script-formulaire/formulaire-contact.php" method="post"> <tr valign="middle"> <td height="21" colspan="2" align="left" background="images/Fond/fond_titre_presse.jpg"><strong class="STitre">Vous souhaitez être contacté par GESTIMUM :</strong></td> </tr> <tr valign="middle"> <td height="9" colspan="2" align="left"> </td> </tr> <tr valign="middle"> <td height="5" colspan="2" align="left"><input name="type" type="radio" class="TexteFicheP" value="Devenir Centre de Solutions"> <span class="TexteFicheP">Vous souhaitez devenir Centre de Solutions GESTIMUM</span> </td> </tr> <tr valign="middle"> <td height="5" colspan="2" align="left"><input name="type" type="radio" class="TexteFicheP" value="Projet d'équipement"> <span class="TexteFicheP">Vous êtes une PME/PMI et vous avez un projet d'équipement</span> </td> </tr> <tr valign="middle"> <td height="10" colspan="2" align="left"><input name="type" type="radio" class="TexteFicheP" value="Expert Comptable/Commissaire aux comptes"> <span class="TexteFicheP">Vous êtes Expert Comptable / Commissaire aux comptes et souhaitez avoir plus d'informations sur notre offre</span> </td> </tr> <tr valign="middle"> <td height="5" colspan="2" align="left"><input name="type" type="radio" class="TexteFicheP" value="Intégration de solution"> <span class="TexteFicheP">Vous êtes éditeur d’une solution verticale et recherchez un progiciel de comptabilité capable de s’intégrer à votre offre</span> </td> </tr> <tr valign="middle"> <td height="5" colspan="2" align="left"><input name="type" type="radio" class="TexteFicheP" value="Journaliste"> <span class="TexteFicheP">Vous êtes Journaliste et cherchez des informations sur GESTIMUM</span> </td> </tr> <tr valign="middle"> <td height="5" colspan="2" align="left"><input name="type" type="radio" class="TexteFicheP" value="Recrutement"> <span class="TexteFicheP">Vous êtes à la recherche d’une opportunité professionnelle</span> </td> </tr> <tr valign="middle"> <td height="5" colspan="2" align="left"><input name="type" type="radio" class="TexteFicheP" value="Demonstration"> <span class="TexteFicheP">Vous souhaitez avoir une démonstration de Gestimum</span> </td> </tr> <tr valign="middle"> <td height="10" colspan="2" align="left"><input name="type" type="radio" class="TexteFicheP" value="Autres"> <span class="TexteFicheP">Autres sujets</span> </td> </tr> <tr valign="middle"> <td height="19" colspan="2" align="left"> </td> </tr> <tr valign="middle"> <td height="19" colspan="2" align="left"> </td> </tr> <tr valign="middle"> <td height="19" colspan="2" align="left" valign="top"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="27%" height="25" align="left" valign="middle" class="TexteFicheP">Nom de l'entreprise* :</td> <td width="28%" height="20" align="left" valign="middle"><input name="Nom-de-l-entreprise" type="text" class="TexteFicheP" size="30" /></td> <td width="45%" class="Style126"> </td> </tr> <tr> <td width="27%" height="25" align="left" valign="middle" class="TexteFicheP">Prénom / Nom* : </td> <td height="25" align="left" valign="middle"><input name="Prenom-Nom" type="text" class="TexteFicheP" size="30" /></td> <td width="45%" class="Style126"> </td> </tr> <tr> <td height="25" align="left" valign="middle" class="TexteFicheP">Téléphone (indicatif du pays svp)* :</td> <td height="25" align="left" valign="middle"><input name="Telephone" type="text" class="TexteFicheP" size="30" /></td> <td width="45%" class="Style126"> </td> </tr> <tr> <td height="25" align="left" valign="middle" class="TexteFicheP">Email* :</td> <td height="25" align="left" valign="middle"><input name="Email" type="text" class="TexteFicheP" size="30" /></td> <td width="45%" class="Style126"> </td> </tr> <tr> <td height="25" align="left" valign="middle" class="TexteFicheP">Votre localisation* : </td> <td height="25" colspan="2" align="left" valign="middle"> <select name='dept' id='dept' onchange='go()'> <option value='-1'>Aucun</option> <?php $select = "SELECT CODE_LOCALISATION, LOCALISATION FROM localisation ORDER BY CODE_LOCALISATION"; $res = mysql_query($select) or die('Erreur SQL !<br>'.$select.'<br>'.mysql_error()); while($row = mysql_fetch_assoc($res)) { echo "<option value='".$row["CODE_LOCALISATION"]."'>".$row["LOCALISATION"]."</option>"; } ?> </select> </td> </tr> <tr> <td height="25" align="left" valign="middle" class="TexteFicheP">Votre Département ou Pays* : </td> <td height="25" colspan="2" align="left" valign="middle"> <div id='ville' style='display:inline'> <select name='ville'> <option value='-1'>Choisir un dept ou un pays</option> </select> </div> </td> </tr> </table> </td> </tr> <tr valign="middle"> <td height="19" colspan="2" align="left" class="pied">* champs obligatoires</td> </tr> <tr> <td height="20" colspan="2" align="center"><img src="images/Decor/barre.gif" width="775" height="1" border="0"></td> </tr> <tr> <td height="19" colspan="2" align="center"> </td> </tr> <tr> <td height="168" colspan="2" align="left" valign="middle"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left" valign="middle"><p><span class="TexteFicheP">Précisez votre demande (facultatif) :</span></p> <p> <textarea name="Description-de-la-demande" cols="100" rows="7" class="TexteFicheP" id="Commentaires"></textarea> </p> </td> </tr> </table> </td> </tr> <tr> <td height="9" colspan="2" align="center"> </td> </tr> <tr> <td height="10" colspan="2" align="center" valign="middle"><a href="#" onClick="document.getElementById('captcha').src = '../crypt/securimage_show.php?' + Math.random(); return false"></a></td> </tr> <tr> <td height="9" align="center" valign="middle"><img id="captcha" src="crypt/securimage_show.php" alt="CAPTCHA Image" /></td> <td height="19" rowspan="2" align="left" valign="middle"><span class="TexteFicheP">Taper le code ci-contre :</span> <input type="text" name="captcha_code" size="10" maxlength="6" /></td> </tr> <tr> <td height="10" align="center" valign="middle"><a href="#" class="TexteFicheP" onClick="document.getElementById('captcha').src = 'crypt/securimage_show.php?' + Math.random(); return false">Recharger l'image</a></td> </tr> <tr> <td colspan="2" align="center"> </td> </tr> <tr> <td height="19" colspan="2" align="center"><input type="submit" value="Envoyer" class="TexteFicheP" /> <input name="input" type="reset" value="Effacer" class="TexteFicheP"/></td> </tr> </form>
Je vous remercie d'avance pour aide.
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 <?php include ('Fichier_connect/x.php'); echo "<select name='ville' id='ville'>"; if(isset($_POST["iddept"])) { $sql = 'SELECT code, pays FROM pays WHERE code_localisation = "' . $_POST['iddept'] . '" ORDER BY code'; $res = mysql_query($sql) or die('Erreur : <br>' . $sql . '<br>' . mysql_error()); while($row = mysql_fetch_assoc($res)) { echo "<option value='".$row["code"]."'>".$row["pays"]."</option>"; } } echo "</select>"; ?>
Partager