Here is and example
Select country (United States) -> appear state combo -> Select State
(California) -> appear city combo ->
i select the wrong country, so i decide to select another country ->
Select country (Canada) -> the state combo show the correct data. But
city cimbo still with the same data as before it doesnt change.

In this case i want the city combo to hide until i select another
state.
In other case, the city combo appear with the data of the country,
until i select a country.

In the controller is this:

def index():
    Country = db().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))])

and int the view is this:

{{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(){
    $('#Pais').change(function(){ ajax('Estado',
['Pais'],'target') });
    $('#State').change(function(){ ajax('City',
['State'],'target1') });
});
$('#Country').change(function(){  $('#Country').attr('onChange',  ajax
('State', ['Country'],'target'))
});
</script>


On 3 nov, 15:41, mdipierro <[email protected]> wrote:
> You do not bother us at all. We are happy to help (if we can).
>
> Can you post the modified code?
>
> On Nov 3, 2:33 pm, Sophie <[email protected]> wrote:
>
>
>
> > I made all the modification but, i still have the problem. The combo
> > is working fine. But the third combo dont hide when i select another
> > country, it still show the data selected before.
>
> > Can i give you my application so you can see my problem better? Tell
> > me if you cant, i dont want to bother.
>
> > On 3 nov, 13:42, mdipierro <[email protected]> wrote:
>
> > > Just
>
> > > $('#Pais').change(function(){ ajax('Estado', ['Pais'],'target') });
>
> > > On Nov 3, 11:40 am, Sophie <[email protected]> wrote:
>
> > > > I sont unsertand the suggestion, something like this?
>
> > > > $('#Pais').attr('onChange',  ajax('Estado', ['Pais'],'target'));
>
> > > > and now
>
> > > > $('#Pais').change(function(){ $('#Pais').attr('onChange',  ajax
> > > > ('Estado', ['Pais'],'target'))
>
> > > > On 3 nov, 10:48, mdipierro <[email protected]> wrote:
>
> > > > > I think it is because:
>
> > > > > 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))])
>
> > > > > should be
>
> > > > > 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))])
>
> > > > > I also suggest that you change
>
> > > > > $(...).attr('onChange', f());
>
> > > > > with
>
> > > > > $(...).change(function(){ f(); });
>
> > > > > On Nov 3, 9:23 am, Sophie <[email protected]> wrote:
>
> > > > > > 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>- Ocultar texto de la cita -
>
> > > > > - Mostrar texto de la cita -- Ocultar texto de la cita -
>
> > > - Mostrar texto de la cita -- Ocultar texto de la cita -
>
> - Mostrar texto de la cita -
--~--~---------~--~----~------------~-------~--~----~
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