Hi all i have a problem with multi combo.

I have three tables Country, State, City. The first time it works
fine, i select a country (Canada), it appears the state combo, i
select a state (Alberta), and appear the city combo. Here is working
fine.

My problem is the second time i want to select a country. I select
anothe country (United States), the city combo dont dissapear and it
still shows the cities of the Alberta state. the country combo
actualizate, and when i selet a country the city combo appear with the
correct data.

So i want to hide the combo when i select another country, so i can
dissapear the inconsistency, and when i select a state it shows again
with the correct data.
The other option is that i select a country and the city combo
actualizates the citys of the country i select, i think this is more
complicated than the first option.

If you could help i would appreaciate it. Here is the code im using:

Controller:

def index():
    country = db((db.state.idCountry==db.country.id)&
(db.city.idState==db.state.id).select
(db.country.ALL,  groupby=db.country.id)
    return dict(country=country)

def state():
    country = request.vars.values()[0]
    state = db(db.state.idCountry == country).select()
    return SELECT(_id="state", _name="state",_type="select",
        _onChange="ajax('"+URL(r=request,f=city)+"',['state'],
'target1');",
        *[OPTION(state[i].nstate, _value=(state[i].id))
for i in range(len(state))])

def city():
    state = request.vars.values()[0]
    city = db(db.city.idState == state).select()
    return SELECT(_id=city,_name=city,*[OPTION(city
[i].nCity, _value=str
    (city[i].id)) for i in range(len(city))])

View:

{{extend 'layout.html'}}
<table>
    <tr><div id="tar">
    <select name="country" id="country" >
        {{for x in country:}}
            <option value={{=x.id}}>{{=x.nCountry}}</option>
        {{pass}}
    </select>
    </div><tr>
    <tr><div id="target"> <div> </tr>
    <tr><div id="target1"> <div> </tr>
    <tr><div id="target2"> <div> </tr>
</table>
<script>
$(document).ready(function(){
    $('#country).attr('onChange',  ajax('state',
['country'],'target'));

----------------------------------------------------------------------
-------> Here i have the problem, the next line doesn't work
----------------------------------------------------------------------
    $('#state).attr('onChange',  ajax('city',
['state'],'target1'));
});
$('#country).change(function(){
    $('#country).attr('onChange',  ajax('state',
['country'],'target'))
});
</script>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to