Here is an abridged demo of vehicle.tcl..
set sql "select category, category_id from moto_category where parent_id IS NULL"
set category_options {"Select a Category" ""}
set category_options [linsert [db_list_of_lists get_vehicle_categories $sql] 0 $category_options]
if {[info exists __refreshing_p] && [string equal $__refreshing_p "1"]} {
set sql "select category, category_id from moto_category where parent_id = :category_id"
set subcategory_options {"Select a Subcategory" ""}
set subcategory_options [linsert [db_list_of_lists get_vehicle_subcategories $sql] 0 $subcategory_options]
} else {
set subcategory_options "-------------"
}
ad_form -name vehicle -form {
vehicle_id:key(moto_vehicle_id_seq)
{sku:text(text),optional {label "SKU"} {html {size 30}}}
{category_id:integer(select),optional {label "Category"} {options {$category_options}}
{html {onchange "document.vehicle.__refreshing_p.value='1';document.vehicle.submit()"}}}
{subcategory_id:integer(select),optional {label "Subcategory"} {options {$subcategory_options}}}
# bunch of vars snipped
} -on_refresh {
# didn't use -on_refresh
# set subcategory_options before ad_form
# because I couldn't find a way to set them here
} -validate {
{sku {$__refreshing_p || 0 < [string length [string trim $sku]]} "\"SKU\" must contain a value"}
{category_id {$__refreshing_p || 0 <[string length $category_id]} "\"Category\" must contain a value"}
{subcategory_id {$__refreshing_p || 0 < [string length $subcategory_id]} "\"Subcategory\" must contain a value"}
# all vars are validated in the same way...
}