Auto-remplir HTML menus déroulants

  • mbenken
  • Born
  • Born
  • No Avatar
  • Inscription: Fév 24, 2011
  • Messages: 2
  • Status: Offline

Message Février 24th, 2011, 8:41 am

Bonjour,
J'ai quelque chose à méditer pour tout le monde. J'ai déroulant "A" qui est une liste de mois et déroulant "B" avec une liste de 5 ans, les années étant l'année en cours moins un à quatre et plus. Là, plus deux zones déroulantes "C" et "D": "C" a une liste de mois et "D" a une liste de 5 ans. Je me demandais s'il y avait une manière de choisir un mois en déroulant "A" et l'année déroulant "B" et de "C" et "D" sera automatiquement rempli avec un mois et l'année est de 23 mois à l'avenir. Par exemple, j'ai choisi de Mar "A" et en 2011 pour "B". Puis "C" et "D" obtenir automatiquement avec février et 2013 respectivement? Est-ce possible? Si oui, dois-je utiliser JavaScript ou PHP considérer le code que j'ai déjà?

Voici mon code à ce jour:
Code: [ Select ]
[php]<span style="margin-right:3px;">Date Range (max range: 24 months)</span><br />
        <select name="from_mo">
    <option></option>
    <option>Jan</option>
    <option>Feb</option>
    <option>Mar</option>
    <option>Apr</option>
    <option>May</option>
    <option>Jun</option>
    <option>Jul</option>
    <option>Aug</option>
    <option>Sep</option>
    <option>Oct</option>
    <option>Nov</option>
    <option>Dec</option>
    </select>
    <select name="from_yr">
    <option></option>
    <?php
    $year = date("Y");
    $i = $year-1;
    while ($i < $year+4) {
        echo '<option>'.$i.'</option>';
        $i++;
    }
    ?>
    </select>
    <span style="margin-left:3px; margin-right:3px;"> to </span>
        <select name="to_mo">
    <option></option>
    <option>Jan</option>
    <option>Feb</option>
    <option>Mar</option>
    <option>Apr</option>
    <option>May</option>
    <option>Jun</option>
    <option>Jul</option>
    <option>Aug</option>
    <option>Sep</option>
    <option>Oct</option>
    <option>Nov</option>
    <option>Dec</option>
    </select>
    <select name="to_yr">
    <option></option>
    <?php
    $year = date("Y");
    $i = $year-1;
    while ($i < $year+4) {
        '<option>'.$i.'</option>';
        $i++;
    }
    ?>
    </select>[/php]
  1. [php]<span style="margin-right:3px;">Date Range (max range: 24 months)</span><br />
  2.         <select name="from_mo">
  3.     <option></option>
  4.     <option>Jan</option>
  5.     <option>Feb</option>
  6.     <option>Mar</option>
  7.     <option>Apr</option>
  8.     <option>May</option>
  9.     <option>Jun</option>
  10.     <option>Jul</option>
  11.     <option>Aug</option>
  12.     <option>Sep</option>
  13.     <option>Oct</option>
  14.     <option>Nov</option>
  15.     <option>Dec</option>
  16.     </select>
  17.     <select name="from_yr">
  18.     <option></option>
  19.     <?php
  20.     $year = date("Y");
  21.     $i = $year-1;
  22.     while ($i < $year+4) {
  23.         echo '<option>'.$i.'</option>';
  24.         $i++;
  25.     }
  26.     ?>
  27.     </select>
  28.     <span style="margin-left:3px; margin-right:3px;"> to </span>
  29.         <select name="to_mo">
  30.     <option></option>
  31.     <option>Jan</option>
  32.     <option>Feb</option>
  33.     <option>Mar</option>
  34.     <option>Apr</option>
  35.     <option>May</option>
  36.     <option>Jun</option>
  37.     <option>Jul</option>
  38.     <option>Aug</option>
  39.     <option>Sep</option>
  40.     <option>Oct</option>
  41.     <option>Nov</option>
  42.     <option>Dec</option>
  43.     </select>
  44.     <select name="to_yr">
  45.     <option></option>
  46.     <?php
  47.     $year = date("Y");
  48.     $i = $year-1;
  49.     while ($i < $year+4) {
  50.         '<option>'.$i.'</option>';
  51.         $i++;
  52.     }
  53.     ?>
  54.     </select>[/php]


Merci,
Michael
  • Anonymous
  • Bot
  • No Avatar
  • Inscription: 25 Feb 2008
  • Messages: ?
  • Loc: Ozzuland
  • Status: Online

Message Février 24th, 2011, 8:41 am

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • Avatar de l’utilisateur
  • Inscription: Déc 20, 2002
  • Messages: 8926
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Message Mars 16th, 2011, 11:59 am

Je suis curieux de savoir si vous jamais trouvé une solution pour cela. Je dirais que cela peut être fait, et à mon avis probablement plus facile avec un peu de PHP et Javascript ensemble. Si c'était à refaire je voudrais utiliser PHP pour remplir tout sur la base d'aujourd'hui date en fonction de votre serveur, puis écrire une sorte de langage Javascript pour changer automatiquement les champs en fonction de ce qui est choisi.
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • mbenken
  • Born
  • Born
  • No Avatar
  • Inscription: Fév 24, 2011
  • Messages: 2
  • Status: Offline

Message Mars 16th, 2011, 1:47 pm

En fait, j'ai découvert une solution. Après le premier «mois» et «année» sont définies dans la première série de menus déroulants, la page est rechargée plaçant un mois et l'année deuxième série de menus déroulants. Il s'agit d'un événement onChange dans la première «année» déroulante. La page a rechargé le mois et l'année choisie dans l'URL. J'utilise la méthode $ _GET l'obtenir les deux valeurs, faire une série de PHP if / then pour le deuxième mois, et les calculs PHP pour la deuxième année. Puis j'ai mis le deuxième mois et les valeurs annuelles des valeurs respectives de la deuxième série de menus déroulants.

Code: [ Select ]
<?php 
    if (isset($_GET['m'])) {
            if ($_GET['m'] == "Jan") {
                $monthrangeend = "Dec";    
            }
            if ($_GET['m'] == "Feb") {
                $monthrangeend = "Jan";    
            }
            if ($_GET['m'] == "Mar") {
                $monthrangeend = "Feb";    
            }
            if ($_GET['m'] == "Apr") {
                $monthrangeend = "Mar";    
            }
            if ($_GET['m'] == "May") {
                $monthrangeend = "Apr";    
            }
            if ($_GET['m'] == "Jun") {
                $monthrangeend = "May";    
            }
            if ($_GET['m'] == "Jul") {
                $monthrangeend = "Jun";    
            }
            if ($_GET['m'] == "Aug") {
                $monthrangeend = "Jul";    
            }
            if ($_GET['m'] == "Sep") {
                $monthrangeend = "Aug";    
            }
            if ($_GET['m'] == "Oct") {
                $monthrangeend = "Sep";    
            }
            if ($_GET['m'] == "Nov") {
                $monthrangeend = "Oct";    
            }
            if ($_GET['m'] == "Dec") {
                $monthrangeend = "Nev";    
            }
        } else {
            $monthrangeend = "";
        }
    if (isset($_GET['y'])) {
            $yearplustwo = $_GET['y'] + 2;
    } else {
      $yearplustwo = "";
    }

        ?>
    <form name="your form name" method="get" action="some action here">
    
    <span style="margin-right:3px;">Date Range (max range: 24 months)</span><br />
        <select name="from_mo" id="frommo">
    <option><?php echo $_GET["m"];?></option>
    <option>Jan</option>
    <option>Feb</option>
    <option>Mar</option>
    <option>Apr</option>
    <option>May</option>
    <option>Jun</option>
    <option>Jul</option>
    <option>Aug</option>
    <option>Sep</option>
    <option>Oct</option>
    <option>Nov</option>
    <option>Dec</option>
    </select>
    <select name="from_yr" id="fromyr" onchange="window.location.href='/members/index.php?m=' + this.form.frommo.options[this.form.frommo.selectedIndex].value + '&y=' + this.form.fromyr.options[this.form.fromyr.selectedIndex].value">
        <option><?php echo $_GET["y"];?></option>
    <?php
                $year = date("Y");
                $i = $year-1;
                while ($i < $year+4) {
                    echo '<option>'.$i.'</option>';
                    $i++;
                }
                ?>
    </select>
    <span style="margin-left:3px; margin-right:3px;"> to </span>
        <select name="to_mo">
    <option><?php echo $monthrangeend;?></option>
    <option>Jan</option>
    <option>Feb</option>
    <option>Mar</option>
    <option>Apr</option>
    <option>May</option>
    <option>Jun</option>
    <option>Jul</option>
    <option>Aug</option>
    <option>Sep</option>
    <option>Oct</option>
    <option>Nov</option>
    <option>Dec</option>
    </select>
    <select name="to_yr">
    <option><?php echo $yearplustwo;?></option>
    <?php
                $year = date("Y");
                $i = $year-1;
                while ($i < $year+4) {
                    echo '<option>'.$i.'</option>';
                    $i++;
                }
                ?>
    </select>
  1. <?php 
  2.     if (isset($_GET['m'])) {
  3.             if ($_GET['m'] == "Jan") {
  4.                 $monthrangeend = "Dec";    
  5.             }
  6.             if ($_GET['m'] == "Feb") {
  7.                 $monthrangeend = "Jan";    
  8.             }
  9.             if ($_GET['m'] == "Mar") {
  10.                 $monthrangeend = "Feb";    
  11.             }
  12.             if ($_GET['m'] == "Apr") {
  13.                 $monthrangeend = "Mar";    
  14.             }
  15.             if ($_GET['m'] == "May") {
  16.                 $monthrangeend = "Apr";    
  17.             }
  18.             if ($_GET['m'] == "Jun") {
  19.                 $monthrangeend = "May";    
  20.             }
  21.             if ($_GET['m'] == "Jul") {
  22.                 $monthrangeend = "Jun";    
  23.             }
  24.             if ($_GET['m'] == "Aug") {
  25.                 $monthrangeend = "Jul";    
  26.             }
  27.             if ($_GET['m'] == "Sep") {
  28.                 $monthrangeend = "Aug";    
  29.             }
  30.             if ($_GET['m'] == "Oct") {
  31.                 $monthrangeend = "Sep";    
  32.             }
  33.             if ($_GET['m'] == "Nov") {
  34.                 $monthrangeend = "Oct";    
  35.             }
  36.             if ($_GET['m'] == "Dec") {
  37.                 $monthrangeend = "Nev";    
  38.             }
  39.         } else {
  40.             $monthrangeend = "";
  41.         }
  42.     if (isset($_GET['y'])) {
  43.             $yearplustwo = $_GET['y'] + 2;
  44.     } else {
  45.       $yearplustwo = "";
  46.     }
  47.         ?>
  48.     <form name="your form name" method="get" action="some action here">
  49.     
  50.     <span style="margin-right:3px;">Date Range (max range: 24 months)</span><br />
  51.         <select name="from_mo" id="frommo">
  52.     <option><?php echo $_GET["m"];?></option>
  53.     <option>Jan</option>
  54.     <option>Feb</option>
  55.     <option>Mar</option>
  56.     <option>Apr</option>
  57.     <option>May</option>
  58.     <option>Jun</option>
  59.     <option>Jul</option>
  60.     <option>Aug</option>
  61.     <option>Sep</option>
  62.     <option>Oct</option>
  63.     <option>Nov</option>
  64.     <option>Dec</option>
  65.     </select>
  66.     <select name="from_yr" id="fromyr" onchange="window.location.href='/members/index.php?m=' + this.form.frommo.options[this.form.frommo.selectedIndex].value + '&y=' + this.form.fromyr.options[this.form.fromyr.selectedIndex].value">
  67.         <option><?php echo $_GET["y"];?></option>
  68.     <?php
  69.                 $year = date("Y");
  70.                 $i = $year-1;
  71.                 while ($i < $year+4) {
  72.                     echo '<option>'.$i.'</option>';
  73.                     $i++;
  74.                 }
  75.                 ?>
  76.     </select>
  77.     <span style="margin-left:3px; margin-right:3px;"> to </span>
  78.         <select name="to_mo">
  79.     <option><?php echo $monthrangeend;?></option>
  80.     <option>Jan</option>
  81.     <option>Feb</option>
  82.     <option>Mar</option>
  83.     <option>Apr</option>
  84.     <option>May</option>
  85.     <option>Jun</option>
  86.     <option>Jul</option>
  87.     <option>Aug</option>
  88.     <option>Sep</option>
  89.     <option>Oct</option>
  90.     <option>Nov</option>
  91.     <option>Dec</option>
  92.     </select>
  93.     <select name="to_yr">
  94.     <option><?php echo $yearplustwo;?></option>
  95.     <?php
  96.                 $year = date("Y");
  97.                 $i = $year-1;
  98.                 while ($i < $year+4) {
  99.                     echo '<option>'.$i.'</option>';
  100.                     $i++;
  101.                 }
  102.                 ?>
  103.     </select>
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • Avatar de l’utilisateur
  • Inscription: Déc 20, 2002
  • Messages: 8926
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Message Mars 16th, 2011, 4:54 pm

Fantastic! Heureux que vous avez trouvé une solution, et merci pour l'affichage comment vous avez fait. On dirait que tu as fini par faire un combo de PHP et JavaScript, tout comme je pense que j'aurais fait :)
Ozzu Hosting - Want your website on a fast server like Ozzu?

Afficher de l'information

  • Total des messages de ce sujet: 4 messages
  • Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 162 invités
  • Vous ne pouvez pas poster de nouveaux sujets
  • Vous ne pouvez pas répondre aux sujets
  • Vous ne pouvez pas éditer vos messages
  • Vous ne pouvez pas supprimer vos messages
  • Vous ne pouvez pas joindre des fichiers
 
 

© 2011 Unmelted, LLC. Ozzu® est une marque déposée de Unmelted, LLC