Bin le plus chiant ensuite, c'est conserver es valeurs pou les remettre dans la formulaire rechargé...Yep ca serai plus simple ca ... à méditer ... cependant mon formulaire est tellement spé que ca me semble difficile![]()
mais merci en tout cas
Code : Tout sélectionner
function reloadList(listfrom, listto, table, defaultvalue, init)
{
if (listfrom.options[listfrom.selectedIndex].value == "")
{
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];
if (defaultvalue)
{
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;
}
}
Code : Tout sélectionner
MON premier select
<select name="nom1" onchange="reloadList(document.forms[0].nom1,document.forms[0].nom2, tableau_titre_valeur_select2, true, false);">
<option value=""> </option>
<option value="valA" >TitreA</option>
<option value="valB" >TitreB</option>
<option value="valC" >TitreC</option>
</select>
MON second select
<select name="nom2">
<option value=""> </option>
<option value="val1" >titre1</option>
<option value="val2" >titre2</option>
<option value="val3" >titre3</option>
<option value="val4" >titre4</option>
<option value="val5" >titre5</option>
</select>
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=""> </option>
<option value="valA" >TitreA</option>
<option value="valB" >TitreB</option>
</select>
MON second select
<select name="nom2">
<option value=""> </option>
<option value="val1" >titreA 1</option>
<option value="val2" >titreA 2</option>
</select>
<input type="submit" id="btprecedent" name="valid" value="valider" />
</body>
</html>
Code : Tout sélectionner
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, defaultvalue, init)
{
if (listfrom.options[listfrom.selectedIndex].value == "")
{
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];
if (defaultvalue)
{
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;
}
}