|
|
|
|
Posté par
nyco2222, le lundi 14 janvier 2008 à 16:56:26
function fillCategory(){
// this function is used to fill the category list on load
addOption(document.drop_list.Category, "Fruits", "Fruits", "");
addOption(document.drop_list.Category, "Games", "Games", "");
addOption(document.drop_list.Category, "Scripts", "Scripts", "");
}
function SelectSubCat(){
// ON selection of category this function will work
removeAllOptions(document.drop_list.SubCat);
addOption(document.drop_list.SubCat, "", "SubCat", "");
if(document.drop_list.Category.value == 'Fruits'){
addOption(document.drop_list.SubCat,"Mango", "Mango");
addOption(document.drop_list.SubCat,"Banana", "Banana");
addOption(document.drop_list.SubCat,"Orange", "Orange");
}
if(document.drop_list.Category.value == 'Games'){
addOption(document.drop_list.SubCat,"Cricket", "Cricket");
addOption(document.drop_list.SubCat,"Football", "Football");
addOption(document.drop_list.SubCat,"Polo", "Polo", "");
}
if(document.drop_list.Category.value == 'Scripts'){
addOption(document.drop_list.SubCat,"PHP", "PHP");
addOption(document.drop_list.SubCat,"ASP", "ASP");
addOption(document.drop_list.SubCat,"Perl", "Perl");
}
}
//////////////////
function removeAllOptions(selectbox)
{
var i;
for(i=selectbox.options.length-1;i>=0;i--)
{
//selectbox.options.remove(i);
selectbox.remove(i);
}
}
function addOption(selectbox, value, text )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}
<!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>(Type a title for your page here)</title> <script language="javascript" src="list.js"></script> </head> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000" onload="fillCategory();"> <FORM name="drop_list" action="yourpage.php" method="POST" > <SELECT NAME="Category" onChange="SelectSubCat();" > <Option value="">Category</option> </SELECT> <SELECT id="SubCat" NAME="SubCat"> <Option value="">SubCat</option> </SELECT> </form> </body> </html>
Configuration: Windows XP Firefox 2.0.0.11
Bonsoir,
Je viens de faire une recherche et un test sur FF 2, ça marche :
selectOption(document.drop_list.SubCat, 2);
function selectOption(selectbox, index) {
selectbox.selectedIndex = index;
}
Pour connaître l'indice sélectionné ou pour sélectionner un indice dans une liste, utiliser .selectedIndex J'ai trouvé l'info ici : http://www.aliasdmc.fr/dom_javascript_html/javascript_html_select_selectedindex.html Raph |
Merci bcp Raph !!!
Cela fait vraiment plaisir de voir qu'il y a des gens bien sur cette toile !!! si jamais tu as besoin de quelque chose, logo, conseils vidéos, hardware, multimédia et photo surtout n'hésites pas à me contacter sur www.artik.ch Je ferai au mieux pour te dépanner!! N. |
Ok, sympa !
A+ Raph |
Salut Raph,
juste j'ai encore une question . Dans le cas où l'on voudrait mettre plusieures fois la sélection dans le même formulaire... regarde l'image tu comprendras. En faisant un simple copier-coller ceci ne fonctionne pas. En recopiant le code et les fonctions et en ajoutant 2 après chaque appelle, chaque variables, ceci ne marche tjs pas ... surement que j'ai fait une erreur de syntaxe mais je suis certain qu'il y a des moyens plus faciles pour régler ce problème. Mercid e ta réponse !! nyco <a href src="http://www.plarel.ch/nyco/chambres.jpg">chambres.jpgi</a> |
Tu pourrais mettre le code qui marche pas?
A priori, tu as peut-être oublié des 2 quelque part (ou tu en as mis en trop ;-). Le fait qu'on en mette plusieurs dans le même formulaire ne devrait rien changer... Raph |
vOILA LE CODE.
J'ai réussi à intégrer les 2 chambres dans 1 form. Cependant, en le testant j'ai remarqué que si p. ex. tu choisis chambre double 1 adulte 1 enfant et que dans l'aoutre chambre tu change ensuite pour une chambre à 4, Le nombere d'enfant dans la chambre n°1 et le nombre d'adultes se remettent par défaut .... Tu saurai comment figer une sélection ? la rendre autonome ?? Merci !!! nYco <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>(Type a title for your page here)</title> <script language="javascript" src="functionlist.js"></script> </head> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000" onload="fillCategory();"> <FORM name="Form1" action="http://montreal.onlinetravel.ch/hotel/session/default/hotel.cgi" method="POST" > <label></label> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><select id="Category" name="Room1" onChange="SelectSubCat();"> </select></td> <td><select id="adulte" name="Room1Adults" onChange="SelectAdCat();"> </select></td> <td><select id="enfant" name="Room1Children"> </select></td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td><select id="Category2" name="Room2" onChange="SelectSubCat();"> </select></td> <td><select id="adulte2" name="Room2Adults" onChange="SelectAdCat();"> </select></td> <td><select id="enfant2" name="Room2Children"> </select></td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> </table> </form> <p> </p> </body> </html> function fillCategory(){
// this function is used to fill the category list on load
addOption(document.Form1.Category, "Chambre simple", "Chambre simple", "@SB");
addOption(document.Form1.Category, "Double a deux lits", "Double a deux lits", "@TB");
addOption(document.Form1.Category, "Ch. double grand lit", "Ch. double grand lit", "@DB");
addOption(document.Form1.Category, "Ch. triple", "Ch. triple", "@TR");
addOption(document.Form1.Category, "Ch. quadruple", "Ch. quadruple", "@QR");
selectOption(document.Form1.Category, 1);
addOption(document.Form1.Room1Children, "0", "0");
addOption(document.Form1.Room1Children, "1", "1");
addOption(document.Form1.Room1Adults, "1", "1");
addOption(document.Form1.Room1Adults, "2", "2");
selectOption(document.Form1.Room1Adults, 1);
///////////////////////////////////
addOption(document.Form1.Category2, "Chambre simple2", "Chambre simple", "@SB");
addOption(document.Form1.Category2, "Double a deux lits2", "Double a deux lits", "@TB");
addOption(document.Form1.Category2, "Ch. double grand lit2", "Ch. double grand lit", "@DB");
addOption(document.Form1.Category2, "Ch. triple2", "Ch. triple", "@TR");
addOption(document.Form1.Category2, "Ch. quadruple2", "Ch. quadruple", "@QR");
selectOption(document.Form1.Category2, 1);
addOption(document.Form1.Room2Children, "0", "0");
addOption(document.Form1.Room2Children, "1", "1");
addOption(document.Form1.Room2Adults, "1", "1");
addOption(document.Form1.Room2Adults, "2", "2");
selectOption(document.Form1.Room2Adults, 1);
}
function SelectAdCat(){
removeAllOptions(document.Form1.Room1Children);
addOption(document.Form1.Room1Children, "0", "0");
removeAllOptions(document.Form1.Room2Children);
addOption(document.Form1.Room2Children, "0", "0");
// si une chambre double ou une chambre a deux lits est sélectionnée:
if (document.Form1.Room1Adults.selectedIndex=="0" && document.Form1.Category.value=="Double a deux lits"){
addOption(document.Form1.Room1Children, "1", "1");
addOption(document.Form1.Room1Children, "2", "2");
}
if (document.Form1.Room1Adults.selectedIndex=="1" && document.Form1.Category.value=="Double a deux lits"){
addOption(document.Form1.Room1Children, "1", "1");
}
if (document.Form1.Room1Adults.selectedIndex=="0" && document.Form1.Category.value=="Ch. double grand lit"){
addOption(document.Form1.Room1Children, "1", "1");
addOption(document.Form1.Room1Children, "2", "2");
}
if (document.Form1.Room1Adults.selectedIndex=="1" && document.Form1.Category.value=="Ch. double grand lit"){
addOption(document.Form1.Room1Children, "1", "1");
}
// Si une chambre triple est sélectionnée:
if(document.Form1.Category.value=="Ch. triple" && document.Form1.Room1Adults.value=="1"){
addOption(document.Form1.Room1Children, "1", "1");
addOption(document.Form1.Room1Children,"2", "2");
}
if(document.Form1.Category.value=="Ch. triple" && document.Form1.Room1Adults.value=="2"){
addOption(document.Form1.Room1Children, "1", "1");
// Si une chambre quadruple est sélectionnée:
}
if(document.Form1.Category.value=="Ch. quadruple" && document.Form1.Room1Adults.value=="3"){
addOption(document.Form1.Room1Children, "1", "1");
}
if(document.Form1.Category.value=="Ch. quadruple" && document.Form1.Room1Adults.value=="2"){
addOption(document.Form1.Room1Children, "1", "1");
addOption(document.Form1.Room1Children,"2", "2");
}
if(document.Form1.Category.value=="Ch. quadruple" && document.Form1.Room1Adults.value=="1"){
addOption(document.Form1.Room1Children, "1", "1");
addOption(document.Form1.Room1Children,"2", "2");
addOption(document.Form1.Room1Children,"3", "3");
}
/////////////////////////////////////
// si une chambre double ou une chambre a deux lits est sélectionnée:
if (document.Form1.Room2Adults.selectedIndex=="0" && document.Form1.Category2.value=="Double a deux lits2"){
addOption(document.Form1.Room2Children, "1", "1");
addOption(document.Form1.Room2Children, "2", "2");
}
if (document.Form1.Room2Adults.selectedIndex=="1" && document.Form1.Category2.value=="Double a deux lits2"){
addOption(document.Form1.Room2Children, "1", "1");
}
if (document.Form1.Room2Adults.selectedIndex=="0" && document.Form1.Category2.value=="Ch. double grand lit2"){
addOption(document.Form1.Room2Children, "1", "1");
addOption(document.Form1.Room2Children, "2", "2");
}
if (document.Form1.Room2Adults.selectedIndex=="1" && document.Form1.Category2.value=="Ch. double grand lit2"){
addOption(document.Form1.Room2Children, "1", "1");
}
// Si une chambre triple est sélectionnée:
if(document.Form1.Category2.value=="Ch. triple2" && document.Form1.Room2Adults.value=="1"){
addOption(document.Form1.Room2Children, "1", "1");
addOption(document.Form1.Room2Children,"2", "2");
}
if(document.Form1.Category2.value=="Ch. triple2" && document.Form1.Room2Adults.value=="2"){
addOption(document.Form1.Room2Children, "1", "1");
// Si une chambre quadruple est sélectionnée:
}
if(document.Form1.Category2.value=="Ch. quadruple2" && document.Form1.Room2Adults.value=="3"){
addOption(document.Form1.Room2Children, "1", "1");
}
if(document.Form1.Category2.value=="Ch. quadruple2" && document.Form1.Room2Adults.value=="2"){
addOption(document.Form1.Room2Children, "1", "1");
addOption(document.Form1.Room2Children,"2", "2");
}
if(document.Form1.Category2.value=="Ch. quadruple2" && document.Form1.Room2Adults.value=="1"){
addOption(document.Form1.Room2Children, "1", "1");
addOption(document.Form1.Room2Children,"2", "2");
addOption(document.Form1.Room2Children,"3", "3");
}
}
function SelectSubCat(){
// ON selection of category this function will work
removeAllOptions(document.Form1.Room1Adults);
removeAllOptions(document.Form1.Room1Children);
addOption(document.Form1.Room1Adults, "1", "1", "1");
addOption(document.Form1.Room1Children, "0", "0", "0");
removeAllOptions(document.Form1.Room2Adults);
removeAllOptions(document.Form1.Room2Children);
addOption(document.Form1.Room2Adults, "1", "1", "1");
addOption(document.Form1.Room2Children, "0", "0", "0");
if(document.Form1.Category.value == 'Chambre simple'){
selectOption(document.Form1.Room1Children, 0);
}
if (document.Form1.Category.value == 'Double a deux lits'){
addOption(document.Form1.Room1Children, "1", "1");
addOption(document.Form1.Room1Adults, "2", "2");
selectOption(document.Form1.Room1Adults, 1);
selectOption(document.Form1.Room1Children, 0);
}
if (document.Form1.Category.value == 'Ch. double grand lit'){
addOption(document.Form1.Room1Children, "1", "1");
addOption(document.Form1.Room1Adults, "2", "2");
selectOption(document.Form1.Room1Adults, 1);
selectOption(document.Form1.Room1Children, 0);
}
if(document.Form1.Category.value == 'Ch. triple'){
addOption(document.Form1.Room1Adults,"2", "2");
addOption(document.Form1.Room1Adults,"3", "3");
selectOption(document.Form1.Room1Adults, 2);
selectOption(document.Form1.Room1Children, 0);
}
if(document.Form1.Category.value == 'Ch. quadruple'){
addOption(document.Form1.Room1Adults,"2", "2");
addOption(document.Form1.Room1Adults,"3", "3");
addOption(document.Form1.Room1Adults,"4", "4");
selectOption(document.Form1.Room1Adults, 3);
selectOption(document.Form1.Room1Children, 0);
}
//////////////////////////////////////////////////
if(document.Form1.Category2.value == 'Chambre simple2'){
selectOption(document.Form1.Room2Children, 0);
}
if (document.Form1.Category2.value == 'Double a deux lits2'){
addOption(document.Form1.Room2Children, "1", "1");
addOption(document.Form1.Room2Adults, "2", "2");
selectOption(document.Form1.Room2Adults, 1);
selectOption(document.Form1.Room2Children, 0);
}
if (document.Form1.Category2.value == 'Ch. double grand lit2'){
addOption(document.Form1.Room2Children, "1", "1");
addOption(document.Form1.Room2Adults, "2", "2");
selectOption(document.Form1.Room2Adults, 1);
selectOption(document.Form1.Room2Children, 0);
}
if(document.Form1.Category2.value == 'Ch. triple2'){
addOption(document.Form1.Room2Adults,"2", "2");
addOption(document.Form1.Room2Adults,"3", "3");
selectOption(document.Form1.Room2Adults, 2);
selectOption(document.Form1.Room2Children, 0);
}
if(document.Form1.Category2.value == 'Ch. quadruple2'){
addOption(document.Form1.Room2Adults,"2", "2");
addOption(document.Form1.Room2Adults,"3", "3");
addOption(document.Form1.Room2Adults,"4", "4");
selectOption(document.Form1.Room2Adults, 3);
selectOption(document.Form1.Room2Children, 0);
}
}
function removeAllOptions(selectbox)
{
var i;
for(i=selectbox.options.length-1;i>=0;i--)
{
//selectbox.options.remove(i);
selectbox.remove(i);
}
}
function addOption(selectbox, value, text)
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}
// this following function is used to select default index of the list
function selectOption(selectbox, index) {
selectbox.selectedIndex = index;
} |
| 04/01 09h47 | Listes déoulantes simples | Excel |
| 07/12 23h48 | Liste déroulante avec saisie semi automatique pour EXCEL | Excel |
| 10/01 11h18 | Supprimer un compte MSN Messenger | MSN Messenger |
| 04/03 22h37 | Action associée au bouton de mise sous tension du boîtier | Windows |
| 04/09 18h05 | Contrôleur hôte USB à haut/bas débit | USB |
| 14/04 09h23 | [Script ajout option ds liste deroulant | 2 |
| 17/06 08h38 | Ajout la valeur d une liste deroulante | 6 |
| 11/02 15h42 | [WD10] ajout valeur liste déroulante (combo) | 0 |
| 14/02 11h26 | Ajout suppression dans une liste déroulante | 0 |
![]() | Ma Liste d'Achats - Faire les courses est une tâche bien compliquée pour les non initiés. Ma liste d'achats est comme son nom l'indique, un... | Catégorie: Environnement de travail Licence: Freeware/gratuit |
![]() | SpaceTime - Pour plus de fluidité et d'ergonomie dans vos recherches sur le web, en mode interactif, c'est encore mieux. Space Time est... | Catégorie: Internet Licence: Freeware/gratuit |
![]() | SpamWars - SpamWars permet de vous protéger contre le spam en agissant tel un filtre gérant une liste blanche. A chaque fois qu'un... | Catégorie: Antispam Licence: Freeware/gratuit |
![]() | Windows XP SP2 - Les Service Packs constituent un moyen pratique, tout en un, d'accéder aux derniers pilotes, outils et améliorations en... | Catégorie: Librairies (DLL) Licence: Freeware/gratuit |
![]() | Listo MCH 785 | Catégorie: Chaîne Hi-Fi | 48.90 € Webdistrib |
![]() | Listo WBC-464 Webcam | Catégorie: Webcam | 9.89 € Webdistrib |
![]() | D-Link DSS-24+ 24-Port 10/100 | Catégorie: Hub/Switch | 117.94 € Amazon.fr |
![]() | Mcad 48-Port 10/100 Mbps | Catégorie: Hub/Switch | 524.65 € Amazon.fr |