I would do something like this:

db.define_table('nominee',Field('name'),Field('region_id',db.Regions))

def get_nominees():
    region_id = request.vars.region_id
    return TAG[''](*[OPTION(r.name,_value=r.id) for r in
db(db.nominee.region_id=region_id).select()])

def get_form():
    script="""
    jQuery(function(){jQuery('input[name=region_id]').keyup(function()
{
       var region_id = jQuery('input[name=region_id]').val();
       jQuery.post('{{=URL('get_nominees')}}', { region_id:
region_id }, function(data, textStatus, jqXHR){
          Query('select[name=nominee]').html(data);
       });});});
    """
    form =
FORM(INPUT(_name='region_id'),SELECT(_name='nominee'),INPUT(_type='submit'),script)

On Apr 25, 11:45 am, Mohamed Sami <melsa...@gmail.com> wrote:
> Hi All,
>
> I'm making a website for elections,
> so i have table for Governorates definition, then region definition
> related to Governorate
>
> also i created a table for nominees which is related to each region
> and each region can have more than one nominee.
>
> also i have a table for voters who is living in a chosen region, and
> he should choose a nominee which is related only to these region.
>
> my table like:
>
> db.define_table('Voters', Field('name', label = 'Full Name'),
>    Field('national_id', label ='National ID', unique= True, length
> =14),
>    Field('email', label ='Email Address'),
>    Field('region_id', db.Regions,label ='Region'),
>    Field('Nominee_id', db.Nominees, label ='Nominee Name'))
>
> i want to create a form for adding new voter and in this form he can
> choose his nominee based on his living region. so i want the form to
> automatically show the governorates list, the regions list based on
> selected governorate, then show the nominees list based on selected
> region.
>
> is there any solution for this.
>
> thank you

Reply via email to