If you want a sample for a javascript postback when drop down changes I have one here:

https://github.com/bernd-wechner/CoGs/blob/master/Leaderboards/templates/CoGs/view_leaderboards.html

It's attached to the select "selNames" which you can trace to the Django view "ajax_Leaderboards" in:

https://github.com/bernd-wechner/CoGs/blob/master/Leaderboards/views.py

if you're patient.

Might be easier to find some simple tutorials than wade through my code, but hey, it's there to look at if you want to see a working demo (almost, that site isn't live yet so can't point you at it running alas).

Regards,

Bernd.

sum abiut wrote:
Thanks heaps for your response. It really clear things up and help me get started.

Cheers,



On Wed, Jun 7, 2017 at 5:05 AM, ludovic coues <cou...@gmail.com <mailto:cou...@gmail.com>> wrote:

    The short answer to "how can I know what option is selected before
    doing the queyr" is "you cannot know".

    Here is a quick drawing of your timeline

    request to your server -> process view (where you do db request) ->
    process template -> send request back to user -> user select an option

    At no point you can go backward in this schema. The trick is to do
    it again.

    The easy solution is to put the select in a form with a submit button
    named "search" or "filter". The first time you show the page, you
    display an empty or full list. When your user submit the form, you
    know which option they have selected.


    If you involve javascript, you can make it as complex as you want.
    First solution is to force a form submission as soon as the value of
    the select change. Next solution is to not reload the whole page but
    do an ajax call. That ajax request can either return the whole list as
    a fragment of HTML to replace the previous list or some formatted
    data, as JSON for example that you can use to replace the data in the
    list. Last solution would be to not use the server for the filtering.
    Send everything to the user and use javascript to filter the data
    according to the value of the select. With no request to your server,
    data will be updated really fast. That solution work really well for
    small to medium amount of data.

    2017-06-06 7:40 GMT+02:00 sum abiut <suab...@gmail.com
    <mailto:suab...@gmail.com>>:
    > Hi,
    > need some directions, i need to query the my database and
    display the result
    > of the query in the table. to do that i want to use a drop down
    menu and get
    > the users to select options from the drop menu on the template.
    >
    > for example if a user select a word from the drop down menu i
    want to filter
    > and query the database base on the option that is selected and
    then display
    > the result.
    >
    > I am confuse on the template side. on the template side how to i
    know if a
    > user select a particular option from the drop down before so
    that i can
    > perform query base on option that was selected from the template
    and display
    > query result base on the respective word that was select.
    >
    > Cheers,
    >
    > --
    > You received this message because you are subscribed to the
    Google Groups
    > "Django users" group.
    > To unsubscribe from this group and stop receiving emails from
    it, send an
    > email to django-users+unsubscr...@googlegroups.com
    <mailto:django-users%2bunsubscr...@googlegroups.com>.
    > To post to this group, send email to
    django-users@googlegroups.com <mailto:django-users@googlegroups.com>.
    > Visit this group at https://groups.google.com/group/django-users
    <https://groups.google.com/group/django-users>.
    > To view this discussion on the web visit
    >
    
https://groups.google.com/d/msgid/django-users/CAPCf-y5ZZdhwV-D71SVQ-50dQDFbhNP7KtBZMR0x7NiBVVQh9A%40mail.gmail.com
    
<https://groups.google.com/d/msgid/django-users/CAPCf-y5ZZdhwV-D71SVQ-50dQDFbhNP7KtBZMR0x7NiBVVQh9A%40mail.gmail.com>.
    > For more options, visit https://groups.google.com/d/optout
    <https://groups.google.com/d/optout>.



    --

    Cordialement, Ludovic Coues
    +33 6 14 87 43 42 <tel:%2B33%206%2014%2087%2043%2042>

    --
    You received this message because you are subscribed to the Google
    Groups "Django users" group.
    To unsubscribe from this group and stop receiving emails from it,
    send an email to django-users+unsubscr...@googlegroups.com
    <mailto:django-users%2bunsubscr...@googlegroups.com>.
    To post to this group, send email to django-users@googlegroups.com
    <mailto:django-users@googlegroups.com>.
    Visit this group at https://groups.google.com/group/django-users
    <https://groups.google.com/group/django-users>.
    To view this discussion on the web visit
    
https://groups.google.com/d/msgid/django-users/CAEuG%2BTbxgksBG-JL%3DgCKEXPaq4%2BO1VbLoJjNo6S1FgYTTP1Qsw%40mail.gmail.com
    
<https://groups.google.com/d/msgid/django-users/CAEuG%2BTbxgksBG-JL%3DgCKEXPaq4%2BO1VbLoJjNo6S1FgYTTP1Qsw%40mail.gmail.com>.
    For more options, visit https://groups.google.com/d/optout
    <https://groups.google.com/d/optout>.




--
You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com <mailto:django-users+unsubscr...@googlegroups.com>. To post to this group, send email to django-users@googlegroups.com <mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPCf-y5wwPHnw5u7_FeaEQnK%2B%3Dj4moC7R8sn-hu2eXf0EbZUvw%40mail.gmail.com <https://groups.google.com/d/msgid/django-users/CAPCf-y5wwPHnw5u7_FeaEQnK%2B%3Dj4moC7R8sn-hu2eXf0EbZUvw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/71a00382-bef1-6b18-1f4c-f3d9ba522859%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to