Dropdown list for age

Solved
ifrit38 -  
 tsiky -
Hello,

I want to create a form with a "age" field.
To choose the age, I would like it to be a dropdown list where the user clicks on their age, but I can't remember the code to use to achieve that.

I know how to make a dropdown list, but how can I avoid having to type in the code for each selectable number? (1 year, 2 years, 3 years, ... up to 99 years)

I hope I have been clear,

Thank you in advance.
Configuration: Windows XP Firefox 2.0.0.14

3 answers

  1. JR des cavernes Posted messages 166 Status Member 84
     
    ```php

    echo "<select name='age'>";
    for($i=1;$i<100;$i++)
    {
    echo "<option value=" .$i .">" .$i ."ans</option>";
    }
    echo "</select>"; ```
    0
  2. kij_82 Posted messages 4102 Registration date   Status Contributor Last intervention   857
     
    Hello,

    You just need to include the setup of the "options" in the list within a loop:

     <SELECT> <?php $ageMin = 1; $ageMax = 99; for( $i=$ageMin; $i <=$ageMax; $i++ ) echo "<OPTION value='".$i."'>".$i."</OPTION>"; ?> </SELECT> 


    Of course, you can't do this loop in simple HTML; you need to use PHP for that.

    --

    ~ Don't forget the "Solved" tag when your issue is... solved :) ~
    0
    1. ifrit38
       
      Thank you all very much.
      0
  3. Enax Posted messages 204 Status Member 145
     
    <select name="age"> <?php for ($i = 1 ; $i < 100 ; $i++) { echo '<option value="' .$i. '">' .$i. ' years</option>' } ?> </select>
    -1
    1. tsiky
       
      It doesn't work, there's always an error for me, what should I do?
      0