11548 sujets

JavaScript, DOM et API Web HTML5

Bonjour,

Je ne parviens à trouver sur le forum un sujet qui me permettrait de résoudre
le problème qui m'occupe actuellement.

J'essaie de faire fonctionner 2 listes déroulantes dépendantes en js + asp, tout fonctionne correctement sous ie6 et 7 mais pas sous firefox, quelqu'un pourrait il m'indiquer dans quelle direction chercher pour résoudre ce problème.

Voici le bout de code

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/test.asp" -->
<%response.buffer=true%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
</head>
<body>


<p>
<form name="monform" action="<%=URL%>" method=post>

<select name="Regions" id="Regions"ize="1" onChange="changeRsRegion()">

<option value="0">Régions</option>
<%
'Liste des régions 
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open MM_test_STRING
set RsRegion=Conn.execute("select * from loc_reg")
while not RsRegion.eof%>
<option value="<%=RsRegion("loc_reg_id")%>"><%=RsRegion("loc_reg_nom")%></option>
<%
RsRegion.movenext
wend%>
</select>
<BR>

<script>
<!--Création de la liste dynamique des départements correspondant à la region selectionner RsRegion("loc_reg_id")
function changeRsRegion() {
choix=document.monform.Regions.value;
document.monform.RsDept.outerHTML=RsRegion[choix]; /*outerHTML fonctionne sous IE Safari Opera pas Firefox innerHTML ne fonctionne pas*/
}

var RsRegion=new Array()
RsRegion[0]="<select name='RsDept' id='RsDept'><option value=0>Départements</option></select>";/*Premiere ligne de la liste avec le titre de la liste*/
<%RsRegion.movefirst
while not RsRegion.eof
temp="<select name='RsDept' id='RsDept'>"
set RsDept=Conn.execute("select * from loc_dept where loc_dept_reg="&RsRegion("loc_reg_id"))
while not RsDept.eof
temp=temp&"<OPTION VALUE="&RsDept("loc_dept_num")&">"&RsDept("loc_dept_nom")&"</option>"
RsDept.movenext
wend
temp= temp&"</select>"%>
RsRegion[<%=RsRegion("loc_reg_id")%>]="<%=temp%>";
<%
RsRegion.movenext
wend
%>


//-->
</script>
<select name="RsDept" id="RsDept" size="1">
<option value="">Départements</option>
</select>

</form>
<%RsRegion.Close()
Set RsRegion = Nothing%>
</body>
</html>



Le code généré


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
</head>
<body>


<p>
<form name="monform" action="" method=post>

<select name="Regions" id="Regions"ize="1" onChange="changeRsRegion()">

<option value="0">Régions</option>

<option value="1">Alsace</option>

<option value="2">Aquitaine</option>

<option value="3">Auvergne</option>

<option value="4">Basse Normandie</option>

<option value="5">Bourgogne</option>

<option value="6">Bretagne</option>

<option value="7">Centre Val de Loire</option>

<option value="8">Champagne Ardenne</option>

<option value="9">Corse</option>

<option value="10">Franche Comté</option>

<option value="11">Haute Normadie</option>

<option value="12">Ile de France</option>

<option value="13">Languedoc Roussillon</option>

<option value="14">Limousin</option>

<option value="15">Lorraine</option>

<option value="16">Midi Pyrenées</option>

<option value="17">Nord Pas de Calais</option>

<option value="18">Pays de la Loire</option>

<option value="19">Picardie</option>

<option value="20">Poitou Charente</option>

<option value="21">Provence Alpes Côte d'Azur</option>

<option value="22">Rhône-Alpes</option>

<option value="23">DOM</option>

<option value="24">TOM</option>

</select>
<BR>

<script>
<!--Création de la liste dynamique des départements correspondant à la region selectionner RsRegion("loc_reg_id")
function changeRsRegion() {
choix=document.monform.Regions.value;
document.monform.RsDept.outerHTML=RsRegion[choix]; /*outerHTML fonctionne sous IE Safari Opera pas Firefox innerHTML ne fonctionne pas*/
}

var RsRegion=new Array()
RsRegion[0]="<select name='RsDept' id='RsDept'><option value=0>Départements</option></select>";/*Premiere ligne de la liste avec le titre de la liste*/

RsRegion[1]="<select name='RsDept' id='RsDept'><OPTION VALUE=67>Bas-Rhin</option><OPTION VALUE=68>Haut-Rhin</option></select>";

RsRegion[2]="<select name='RsDept' id='RsDept'><OPTION VALUE=24>Dordogne</option><OPTION VALUE=33>Gironde</option><OPTION VALUE=40>Landes</option><OPTION VALUE=47>Lot et Garonne</option><OPTION VALUE=64>Pyrénées Atlantiques</option></select>";

RsRegion[3]="<select name='RsDept' id='RsDept'><OPTION VALUE=03>Allier</option><OPTION VALUE=15>Cantal</option><OPTION VALUE=43>Haute Loire</option><OPTION VALUE=63>Puy de Dôme</option></select>";

RsRegion[4]="<select name='RsDept' id='RsDept'><OPTION VALUE=14>Calvados</option><OPTION VALUE=50>Manche</option><OPTION VALUE=61>Orne</option></select>";

RsRegion[5]="<select name='RsDept' id='RsDept'><OPTION VALUE=21>Côte d’Or</option><OPTION VALUE=58>Nièvre</option><OPTION VALUE=71>Saône et Loire</option><OPTION VALUE=89>Yonne</option></select>";

RsRegion[6]="<select name='RsDept' id='RsDept'><OPTION VALUE=22>Côtes-d'Armor</option><OPTION VALUE=29>Finistère</option><OPTION VALUE=35>Ille-et-Vilaine</option><OPTION VALUE=56>Morbihan</option></select>";

RsRegion[7]="<select name='RsDept' id='RsDept'><OPTION VALUE=18>Cher</option><OPTION VALUE=28>Eure et Loire</option><OPTION VALUE=36>Indre</option><OPTION VALUE=37>Indre et Loire</option><OPTION VALUE=41>Loir et Cher</option><OPTION VALUE=45>Loiret</option></select>";

RsRegion[8]="<select name='RsDept' id='RsDept'><OPTION VALUE=08>Ardennes</option><OPTION VALUE=10>Aube</option><OPTION VALUE=51>Marne</option><OPTION VALUE=52>Haute-Marne</option></select>";

RsRegion[9]="<select name='RsDept' id='RsDept'><OPTION VALUE=2A>Corse du Sud</option><OPTION VALUE=2B>Corse du Nord</option></select>";

RsRegion[10]="<select name='RsDept' id='RsDept'><OPTION VALUE=25>Doubs</option><OPTION VALUE=39>Jura</option><OPTION VALUE=70>Haute Saone</option><OPTION VALUE=90>Territoire de Belfort</option></select>";

RsRegion[11]="<select name='RsDept' id='RsDept'><OPTION VALUE=27>Eure</option><OPTION VALUE=76>Seine-Maritime</option></select>";

RsRegion[12]="<select name='RsDept' id='RsDept'><OPTION VALUE=75>Paris</option><OPTION VALUE=77>Seine-et-Marne</option><OPTION VALUE=78>Yvelines</option><OPTION VALUE=91>Essonne</option><OPTION VALUE=92>Hauts-de-Seine</option><OPTION VALUE=93>Seine-Saint-Denis</option><OPTION VALUE=94>Val-de-Marne</option><OPTION VALUE=95>Val-d'Oise</option></select>";

RsRegion[13]="<select name='RsDept' id='RsDept'><OPTION VALUE=11>Aude</option><OPTION VALUE=30>Gard</option><OPTION VALUE=34>Hérault</option><OPTION VALUE=48>Lozère</option><OPTION VALUE=66>Pyrénées Orientales</option></select>";

RsRegion[14]="<select name='RsDept' id='RsDept'><OPTION VALUE=19>Corrèze</option><OPTION VALUE=23>Creuse</option><OPTION VALUE=87>Haute Vienne</option></select>";

RsRegion[15]="<select name='RsDept' id='RsDept'><OPTION VALUE=54>Meurthe-et-Moselle</option><OPTION VALUE=55>Meuse</option><OPTION VALUE=57>Moselle</option><OPTION VALUE=88>Vosges</option></select>";

RsRegion[16]="<select name='RsDept' id='RsDept'><OPTION VALUE=09>Ariège</option><OPTION VALUE=12>Aveyron</option><OPTION VALUE=31>Haute Garonne</option><OPTION VALUE=32>Gers</option><OPTION VALUE=46>Lot</option><OPTION VALUE=65>Hautes Pyrénées</option><OPTION VALUE=81>Tarn</option><OPTION VALUE=82>Tarn et Garonne</option></select>";

RsRegion[17]="<select name='RsDept' id='RsDept'><OPTION VALUE=59>Nord</option><OPTION VALUE=62>Pas-de-Calais</option></select>";

RsRegion[18]="<select name='RsDept' id='RsDept'><OPTION VALUE=02>Aisne</option><OPTION VALUE=44>Loire-Atlantique</option><OPTION VALUE=49>Maine-et-Loire</option><OPTION VALUE=53>Mayenne</option><OPTION VALUE=60>Oise</option><OPTION VALUE=72>Sarthe</option><OPTION VALUE=80>Somme</option><OPTION VALUE=85>Vendée</option></select>";

RsRegion[19]="<select name='RsDept' id='RsDept'><OPTION VALUE=16>Charentes</option><OPTION VALUE=17>Charentes Maritime</option><OPTION VALUE=79>Deux Sèvres</option><OPTION VALUE=86>Vienne</option></select>";

RsRegion[20]="<select name='RsDept' id='RsDept'><OPTION VALUE=04>Alpes de Haute provence</option><OPTION VALUE=05>Hautes Alpes</option><OPTION VALUE=06>Alpes Maritimes</option><OPTION VALUE=13>Bouches du Rhône</option><OPTION VALUE=83>Var</option><OPTION VALUE=84>Vaucluse</option></select>";

RsRegion[21]="<select name='RsDept' id='RsDept'><OPTION VALUE=01>Ain</option><OPTION VALUE=07>Ardèche</option><OPTION VALUE=26>Drôme</option><OPTION VALUE=38>Isère</option><OPTION VALUE=42>Loire</option><OPTION VALUE=69>Rhône</option><OPTION VALUE=73>Savoie</option><OPTION VALUE=74>Haute Savoie</option></select>";

RsRegion[22]="<select name='RsDept' id='RsDept'></select>";

RsRegion[23]="<select name='RsDept' id='RsDept'><OPTION VALUE=971>Guadeloupe</option><OPTION VALUE=972>Martinique</option><OPTION VALUE=973>Guyane</option><OPTION VALUE=974>Réunion</option></select>";

RsRegion[24]="<select name='RsDept' id='RsDept'><OPTION VALUE=975>Saint Pierre et Miquelon</option><OPTION VALUE=976>Mayotte</option><OPTION VALUE=984>Terres Australes et Antartiques</option><OPTION VALUE=986>Wallis et Futuna</option><OPTION VALUE=987>Polynésie Française</option><OPTION VALUE=988>Nouvelle Calédonie</option></select>";



//-->
</script>
<select name="RsDept" id="RsDept" size="1">
<option value="">Départements</option>
</select>

</form>

</body>
</html>

D'avance merci pour l'info et merci aux personnes qui enrichissent ce forum de leurs connaissances.
Modifié par Loto (17 Nov 2006 - 14:53)
Bonjour.


document.monform.listeB.outerHTML=liste choix ;


outerHTML quésaco ? Si c'est un gri-gri à Bill GATES, en tout cas, c'est pas DOM.

N'est-pas remplaçable par innerHTML ? C'est pas DOM non plus, mais c'est lu par firefox...
Oui, et le code ASP n'est pas pertinent pour te dire d'où vient l'erreur, et surtout peu lisible (c'est d'ailleurs indiqué dans la règle 13 du forum). Le code HTML généré serait bien plus intéressant.

je ne sais pas si Firefox supporte la syntaxe document.nomDuFormulaire...