0

I need to dynamically change a forum based on a selection of a drop down menu. The forum will have a menu and two textboxes. All the information is in a Postgresql database, like so:

 |  Dropdown |  Text1  |  Text 2  |
---------------------------------
 |     1     |   red   |   blue   |
 |     2     |   dog   |    cat   |

This this choice_table. Now, in my HTML code I have put the following to figure out which choice has been selected:

 <script>
        $("#id_drop_down").on('change', function() {
          if ($(this).val() !== ""){
            $choice = $(this).val()
            alert($choice + " has been selected!")
          };
        });
      </script>

My next step is to use $choice to use as an identifier to query into the choice_table and populate Text1 and Text2. How can I use $choice to query my database?

3
  • 1
    What is the backend? Commented May 3, 2017 at 12:39
  • @ClodoaldoNeto I'm using the Django framework, if that's helpful. Commented May 3, 2017 at 12:44
  • So you need to write a Django view that your Ajax talks to. Where are you having trouble? Commented May 3, 2017 at 13:06

1 Answer 1

1

You must create a view that handles your ajax calls and returns data in appropriate format, for example JSON. Then, make ajax requests from client html page on this view to get your data.

Sign up to request clarification or add additional context in comments.

1 Comment

I didn't realize that a view handled the ajax information, I thought is was all done in the script XD. Well that's what I'm working on now, got it partly working. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.