[Flask] Java script dynamic dropdown

Mazzei, Stephen Andrew Stephen.Mazzei at asrcfederal.com
Mon Aug 1 15:54:01 EDT 2016


Good afternoon,

You all have been incredibly helpful so I am looking for a little more help :) . I am trying to create a dynamic drop down menu based on another dropdown menu. Similar to the <State> <City> type thing.

I have the following

    <script type=text/javascript>
        $('#application').on('change', function() {
            $("#result").empty();
            application_name = $("#application option:selected").text();
            application_id = $("#application option:selected").val();
            $.getJSON('/_parse_models', {
                a: application_name,
                b: application_id
            }, function(data) {
                var options = $("#result");
                $.each(data, function() {
                    options.append($("<option />").val(this).text(this));
                });
            });
            return false;
        });
    </script>

    <div class="container">
        <hr/>
        <div>
        <p>
        <td><select id='application'>
            <option value='1'>1</option>
            <option value='2'>2</option>
            <option value='3'>3</option>
        </select></td>
        <td><select name='result'>
            <option value='{{result}}'>{{result}}</option>
        </select></td>
        </form>
        </div>
    </div>

@mod_validations.route('/_parse_models')
def list_models():
    id = request.args.get('b', 0)
    print id
    return jsonify(result=id)


If I can just receive a little help on getting this part to work, I can figure out how to apply real data. Thank you

________________________________

The preceding message (including attachments) is covered by the Electronic Communication Privacy Act, 18 U.S.C. sections 2510-2512, is intended only for the person or entity to which it is addressed, and may contain information that is confidential, protected by attorney-client or other privilege, or otherwise protected from disclosure by law. If you are not the intended recipient, you are hereby notified that any retention, dissemination, distribution, or copying of this communication is strictly prohibited. Please reply to the sender that you have received the message in error and destroy the original message and all copies.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20160801/ca2c2d1e/attachment.html>


More information about the Flask mailing list