formulaire différent selon le choix d'une liste

Eléphant du PHP | 357 Messages

14 oct. 2005, 10:52

Voilà j'ai trouvé !!!! je vous montre la solution, je dis pas que c'est la meilleur mais ca marche :
sur le fichier formulaire:

Code : Tout sélectionner

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" type="text/css" media="screen, projection" href="formulaire.css" /> <script src="control.js" type="text/javascript"></script> <title>formulaire</title> </head> <body> <form action="<?php echo $action; ?>" method="post"> <select name="nom1" onchange="reloadList(document.forms[0].nom1,document.forms[0].nom2, tableau_titre_valeur_select2, true, false);"> <option value="">&nbsp;</option> <option value="valA" >TitreA</option> <option value="valB" >TitreB</option> </select> MON second select <select name="nom2"> <option></option> </select> <input type="submit" id="btprecedent" name="valid" value="valider" /> </body> </html>
et pour le fichier JS :

Code : Tout sélectionner

var secteur_activite_csp=new Array(); tableau_titre_valeur_select2[2]=new Array(5); tableau_titre_valeur_select2[2][0]="valA"; tableau_titre_valeur_select2[2][1]="01"; tableau_titre_valeur_select2[2][2]="titreA 1"; tableau_titre_valeur_select2[2][3]="02"; tableau_titre_valeur_select2[2][4]="TitreA 2"; tableau_titre_valeur_select2[3]=new Array(5); tableau_titre_valeur_select2[3][0]="valB"; tableau_titre_valeur_select2[3][1]="10"; tableau_titre_valeur_select2[3][2]="titreB 1"; tableau_titre_valeur_select2[3][3]="15"; tableau_titre_valeur_select2[3][4]="titreB 2"; function reloadList(listfrom, listto, table,init) { if (listfrom.options[listfrom.selectedIndex].value == "") { listto.getOptionValue=1; listto.options.length = 1; listto.options[0].value = ""; listto.options[0].text = ""; } else { for (i=0;i < table.length;i++) { if (table[i][0] == listfrom.options[listfrom.selectedIndex].value) { beginIndex = 0; tableCurrent = table[i]; listto.options[0].value = ""; listto.options[0].text = ""; beginIndex = 1; listto.options.length = (tableCurrent.length - 1)/2 + beginIndex; var sizeTable = tableCurrent.length; for (j=1; j < sizeTable; j = j + 2) { listto.options[(j - 1) / 2 + beginIndex].value = tableCurrent[j]; listto.options[(j - 1) / 2 + beginIndex].text = tableCurrent[j + 1]; } } } if (!init) listto.selectedIndex=0; } }
Merci a tous pour votre aide surtout heddicmi.
Cette solution marche si vous voulez des explications n'hesitez pas :wink: