Dropdown list for age
Solved
ifrit38
-
tsiky -
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.
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 réponses
```php
echo "<select name='age'>";
for($i=1;$i<100;$i++)
{
echo "<option value=" .$i .">" .$i ."ans</option>";
}
echo "</select>"; ```
echo "<select name='age'>";
for($i=1;$i<100;$i++)
{
echo "<option value=" .$i .">" .$i ."ans</option>";
}
echo "</select>"; ```
Hello,
You just need to include the setup of the "options" in the list within a loop:
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 :) ~
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 :) ~