I am using the web2py slice from 
http://www.web2pyslices.com/slice/show/1526/cascading-drop-down-lists-with-ajax-2.

I noticed that the second drop down is getting populated correctly on 
firefox but on internet explorer, it is not working (Tested on IE9).

I verified that on IE, on changing the value, an additional select 
statement is seen which seems to be causing the issue :-

IE Debug Snapshot (Before any change in selection)



IE Debug Snapshot (After change in first drop down)



Can anyone please help to resolve this on IE

*Views*

{{extend 'layout.html'}}

    <form enctype="multipart/form-data" action="{{URL()}}" method="post">
    <select name='category_name'
    onchange="jQuery('#maker_name').empty();
    ajax('maker', ['category_name'], 'maker_name');">
    {{for category in categories:}}
    <option value="{{=category.id}}"
    {{=" selected='selected'" if 
str(category.id)==request.vars.category_name else ""}}>
    {{=category.Name}}
    </option>
    {{pass}}
    </select>
    <select id='maker_name' name='maker_name' >
    {{for maker in makers:}}
    <option value="{{=maker.id}}"
    {{=XML(" selected='selected'") if 
str(maker.id)==request.vars.maker_name else ""}}>
    {{=maker.Name}}</option>
    {{pass}}
    </select>
    <input type="submit" value='Submit'>
    </form>

*Controller :*

def index():
    print request.vars
    grid = {}
    if request.vars.maker_name:
        query = (db.Product.Maker_ID==request.vars.maker_name)
        grid = 
SQLFORM.grid(query=query,csv=False,create=False,deletable=False,)
        lists = 
db(db.Product.Maker_ID==request.vars.maker_name).select(db.Product.ALL)
        themakers = 
db(db.Maker.id==request.vars.maker_name).select(db.Maker.ALL)      
    else:
        lists = db(db.Product.Maker_ID==1).select(db.Product.ALL)
        themakers = db(db.Maker.id==1).select(db.Maker.ALL)
    categories = db().select(db.Category.ALL)
    if request.vars.category_name:
        makers = 
db(db.Maker.Category_ID==request.vars.category_name).select(db.Maker.ALL)
    else:
        makers = db(db.Maker.Category_ID==1).select(db.Maker.ALL)
    return dict(lists=lists, categories=categories, makers=makers, 
themakers=themakers, grid=grid)

def maker():
    makers = 
db(db.Maker.Category_ID==request.vars.category_name).select(db.Maker.ALL)
    result = "<select name='maker_name'>"
    for maker in makers:
        result += "<option value='" + str(maker.id) + "'>" + maker.Name + 
"</option>"  
    result += "</select>"
    return XML(result)

*Models :*

db.define_table('Category',
    Field('Name'))

db.define_table('Maker',
    Field('Name'),
    Field('Category_ID', db.Category),
    Field('Note', 'text'))

db.define_table('Product',
    Field('Part_Number'),
    Field('Maker_ID', db.Maker),
    Field('List_Price', 'decimal(13,2)'),
    Field('Special_Price', 'decimal(13,2)'))

db.Category.Name.requires = IS_NOT_EMPTY()
db.Maker.Name.requires = IS_NOT_EMPTY()
db.Maker.Category_ID.requires = IS_IN_DB(db, db.Category.id, '%(Name)s')
db.Product.Part_Number.requires = IS_NOT_EMPTY()
db.Product.Maker_ID.requires = IS_IN_DB(db, db.Maker.id, '%(Name)s')

if db(db.Category.id>0).count() == 0:
    db.Category.insert(Name='PC')
    db.Category.insert(Name='Smart Phone')

    db.Maker.insert(Name='Toshiba', Category_ID=1, Note='Good Maker')
    db.Maker.insert(Name='HP', Category_ID=1, Note='Good Maker')
    db.Maker.insert(Name='Dell', Category_ID=1, Note='Good Maker')
    db.Maker.insert(Name='Apple', Category_ID=2, Note='Good Maker')
    db.Maker.insert(Name='Samsung', Category_ID=2, Note='Good Maker')

    db.Product.insert(Part_Number='Toshiba Product A', Maker_ID=1, 
List_Price=1000, Special_Price=500)
    db.Product.insert(Part_Number='Toshiba Product B', Maker_ID=1, 
List_Price=1500, Special_Price=1000)
    db.Product.insert(Part_Number='Toshiba Product C', Maker_ID=1, 
List_Price=2000, Special_Price=1500)
    db.Product.insert(Part_Number='Toshiba Product D', Maker_ID=1, 
List_Price=2500, Special_Price=2000)
    db.Product.insert(Part_Number='Toshiba Product E', Maker_ID=1, 
List_Price=3000, Special_Price=2500)
    db.Product.insert(Part_Number='Toshiba Product F', Maker_ID=1, 
List_Price=3500, Special_Price=3500)

    db.Product.insert(Part_Number='HP Product A', Maker_ID=2, 
List_Price=1000, Special_Price=500)
    db.Product.insert(Part_Number='HP Product B', Maker_ID=2, 
List_Price=1500, Special_Price=1000)
    db.Product.insert(Part_Number='HP Product C', Maker_ID=2, 
List_Price=2000, Special_Price=1500)
    db.Product.insert(Part_Number='HP Product D', Maker_ID=2, 
List_Price=2500, Special_Price=2000)
    db.Product.insert(Part_Number='HP Product E', Maker_ID=2, 
List_Price=3000, Special_Price=2500)
    db.Product.insert(Part_Number='HP Product F', Maker_ID=2, 
List_Price=3500, Special_Price=3500)

    db.Product.insert(Part_Number='Dell Product A', Maker_ID=3, 
List_Price=1000, Special_Price=500)
    db.Product.insert(Part_Number='Dell Product B', Maker_ID=3, 
List_Price=1500, Special_Price=1000)
    db.Product.insert(Part_Number='Dell Product C', Maker_ID=3, 
List_Price=2000, Special_Price=1500)
    db.Product.insert(Part_Number='Dell Product D', Maker_ID=3, 
List_Price=2500, Special_Price=2000)
    db.Product.insert(Part_Number='Dell Product E', Maker_ID=3, 
List_Price=3000, Special_Price=2500)
    db.Product.insert(Part_Number='Dell Product F', Maker_ID=3, 
List_Price=3500, Special_Price=3500)

    db.Product.insert(Part_Number='Apple Product A', Maker_ID=4, 
List_Price=1000, Special_Price=500)
    db.Product.insert(Part_Number='Apple Product B', Maker_ID=4, 
List_Price=1500, Special_Price=1000)
    db.Product.insert(Part_Number='Apple Product C', Maker_ID=4, 
List_Price=2000, Special_Price=1500)
    db.Product.insert(Part_Number='Apple Product D', Maker_ID=4, 
List_Price=2500, Special_Price=2000)
    db.Product.insert(Part_Number='Apple Product E', Maker_ID=4, 
List_Price=3000, Special_Price=2500)
    db.Product.insert(Part_Number='Apple Product F', Maker_ID=4, 
List_Price=3500, Special_Price=3500)

    db.Product.insert(Part_Number='Samsung Product A', Maker_ID=5, 
List_Price=1000, Special_Price=500)
    db.Product.insert(Part_Number='Samsung Product B', Maker_ID=5, 
List_Price=1500, Special_Price=1000)
    db.Product.insert(Part_Number='Samsung Product C', Maker_ID=5, 
List_Price=2000, Special_Price=1500)
    db.Product.insert(Part_Number='Samsung Product D', Maker_ID=5, 
List_Price=2500, Special_Price=2000)
    db.Product.insert(Part_Number='Samsung Product E', Maker_ID=5, 
List_Price=3000, Special_Price=2500)
    db.Product.insert(Part_Number='Samsung Product F', Maker_ID=5, 
List_Price=3500, Special_Price=3500)

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to