I have 2 select boxes. I managed to auto-populate second select box based 
on value from the first one. All of the code below works just fine when I 
create new record - second select is being populated. However, when I try 
to update the same record, select_2 does not get populated, as if the *
department* variable never reached the *populate* function. As a result, 
there's a view rendered within select_2 instead of <option></option> 
elements. This occurs only in the update form.

The script passing *department *variable from select_1:

<script>
    $('#select_1').change(function() {
        ajax('populate', ['department'], 'select_2');
    });
</script>

*populate *function which uses "department" var to get respective data:

def populate():

    ranks = db(db.rank.department_id == 
request.vars.department).select(db.rank.id, db.rank.name, 
orderby=db.rank.name)

    result = ""

    for r in ranks:
        result += "<option value='" + str(r.id) + "'>" + r.name + 
"</option>"

    return XML(result)

view:

<div class="w2p_fw">
    {{if request.vars.department:}}
        <select class="generic-widget" id="seafarer_experience_rank" 
name="rank">
            {{=XML(result)}}
        </select>
    {{else:}}
        {{=form.custom.widget.rank}}
    {{pass}}
</div>


-- 

--- 
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.


Reply via email to