Currently you can perfectly use Integer form field.
The integer form field type provides a select box with a range of integer values.
<field
name="age"
type="integer"
default="1"
label="Age"
description="age"
first="1"
last="100"
step="1"
/>
first would be minimum age and last would be maximum age.
ALTERNATIVE
Another option would be to create custom form field. This gives you more flexibility if you want to extend your field.
administrator/components/[name of your component]/models/fields/Age.php
<?php
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
jimport('joomla.form.formfield');
class JFormFieldAge extends JFormField {
protected $type = 'Age';
// getLabel() left out, no need to overwrite it (at least for this example)
public function getInput() {
// Define min and max ages, if not set by field, defaults to 1 and 100.
$minAge = isset($this->element['min']) ? $this->element['min'] : 1;
$maxAge = isset($this->element['max']) ? $this->element['max'] : 100;
$html = '<select id="'.$this->id.'" name="'.$this->name.'">';
// Loop
for ($i = $minAge; $i <= $maxAge; $i++) {
$html .= '<option value="'.$i.'">'.$i.'</option>';
}
$html .= '</select>';
return $html;
}
}
Load your fields in your extension main file.
JForm::addFieldPath(JPATH_COMPONENT . '/models/fields'); // Change the path for your needs
XML
In addition, you may need to add the field path to the parent :
<fieldset addfieldpath="/administrator/components/<component name>/models/fields">
Again, change the path for your needs.
And finally, use your custom field type
<field
name="age"
type="Age"
description="age"
label="Age"
min="18"
max="90"
size="1" />
Read more about creating a custom form field type.