Yes, I checked: the load function is being triggered and *dpt* variable is
being set in the function every time I select an option from the first
drop-down.
Changed the function so it uses OPTION helper:
def add_experience():
add_experience = crud.create(db.seafarer_experience, next=(URL('seafarer',
'profile')), _class='formstyle')
print request.vars.dpt
ranks = db(db.rank.department_id ==
request.vars.dpt).select(orderby=db.rank.name)
result = ""
for r in ranks:
result += OPTION(r.name, _value=r.id)
return dict(add_experience=add_experience, result=result)
The respective view fragment:
<div class="w2p_fw">
<select class="generic-widget" id="seafarer_experience_rank"
name="rank">
{{=result}}
</select>
</div>
(The HTML is fixed just for now, I've cut the dynamic code to test the
auto-populating only...)
On Monday, June 17, 2013 12:47:57 AM UTC+2, villas wrote:
>
> Hmm I'm not sure you have given enough info. Anyhow:
>
> Check in Firebug whether the load function is being triggered.
> Place print statements in your function to test that the variables are
> being set.
> Bear in mind that "return dict(...)" will render a complete page layout.
> I wonder if that is what you want?
> Check out the SELECT and OPTION helpers.
>
>
> On Sunday, 16 June 2013 23:10:12 UTC+1, lesssugar wrote:
>>
>> I need to auto-populate my 'ranks' drop-down based on the value selected
>> in the 'department' one.
>>
>> This is my script:
>>
>> <script>
>> $("#department").change(function() {
>> $("#ranks").load("?dpt=" + $("#department").val());
>> });
>> </script>
>>
>> As you can see, I pass *dpt *var to my current function. This is its
>> code:
>>
>> def add_experience():
>>
>> ranks = db(db.rank.department_id == request.vars.dpt).select(orderby=
>> db.rank.name)
>>
>> result = ""
>>
>> for r in ranks:
>> result += "<option value='" + str(r.id) + "'>" + r.name +
>> "</option>"
>>
>>
>> return dict(result=XML(result))
>>
>> When I select a value in the first drop-down, a request is being sent to
>> [controller]/add_experience?dpt=[value selected]. However the second
>> drop-down does not populate with respective data - it's empty. I'm clearly
>> missing something. Any help?
>>
>>
--
---
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/groups/opt_out.