I have a three dropdown and the value will be dynamically changed using
ajax. It's working fine but something is wrong. In second dropdown
(id="lead_name"), I specify jQuery('#model_name') but it's
actually jQuery('#leadl_name') but then when the value for the second drop
changed, the value disappear from the second and third. When I keep the
current way (which is wrong name) it's working as expected.... Do you guys
know what's wrong?
This is my view
<form enctype="multipart/form-data" action="{{URL()}}" method="post">
<tr>
<td><select name='model_name' onchange="jQuery('#model_name'
).empty();
ajax('lead_ajax', ['model_name'], 'lead_name');">
{{for model in models:}}
<option value="{{=model.Name}}"
{{=" selected='selected'" if str(model.Name)=
=request.vars.model_name else ""}}>
{{=model.Name}}
</option>
{{pass}}
</select></td>
<td><select id='lead_name' name='lead_name' onchange="jQuery
('#model_name').empty();
ajax('block_ajax', ['lead_name'], 'block_name');">
{{for lead in leads:}}
<option value="{{=lead.Name}}"
{{=" selected='selected'" if str(lead.Name)=
=request.vars.lead_name else ""}}>
{{=lead.Name}}
</option>
{{pass}}
</select></td>
<td><select id='block_name' name='block_name'>
{{for block in blocks:}}
<option value="{{=block.Name}}"
{{=" selected='selected'" if str(block.Name)=
=request.vars.block_name else ""}}>
{{=block.Name}}
</option>
{{pass}}
</select></td>
<td></td>
<td></td>
<td><input type="submit" value='Submit'></td>
</tr>
</form>
My controller
def index():
response.title='KR Quick Delivery Service'
if request.vars.model_name:
lists = db((db.KR_Product.Model==request.vars.model_name) & (db.
KR_Product.Lead==request.vars.lead_name) & (db.KR_Product.Block==request.
vars.block_name)).select(db.KR_Product.ALL)
else:
lists=''
models = db().select(db.KR_Model.ALL)
leads = db(db.KR_Lead.ModelName == '20').select(db.KR_Lead.ALL)
blocks = db(db.KR_Block.LeadName == '01').select(db.KR_Block.ALL)
return dict(lists=lists,models=models,leads=leads,blocks=blocks)
def lead_ajax():
leads = db(db.KR_Lead.ModelName==request.vars.model_name).select(db.
KR_Lead.ALL)
result = ''
for lead in leads:
result += "<option value='" + lead.Name + "'>" + lead.Name +
"</option>"
return XML(result)
def block_ajax():
blocks = db(db.KR_Block.LeadName==request.vars.lead_name).select(db.
KR_Block.ALL)
result = ''
for block in blocks:
result += "<option value='" + block.Name + "'>" + block.Name +
"</option>"
return XML(result)
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.