Reputation: 51
I have a select option box with the value from database. If i select an option the other three text field will be loaded with data from database based on select option id or primary key value. how do i do that in django , jquery. Thank you so much
Upvotes: 0
Views: 1468
Reputation: 13001
Create a Django view which takes the select option id or primary key as a parameter. Have the view return the values you'll need in the other three text fields.
On the page with the form you'll need to have a bit of jQuery that, e.g. upon change of the selection field, calls the Django view and uses the result to fill the text fields.
How you'll format the result of the view is up to you. You could make it as simple as a comma separated list, you could also probably do something with JSON or get even fancier.
Upvotes: 0
Reputation: 12195
In the spirit of teaching a man to fish, rather than just giving him some to eat...
jQuery.ajax()
GET call to a view in your Django app that specifically sends back the data you want to add to the text fields (I'd recommend it comes back as JSON rather than HTML or plain text, as it'll be easier to process on the client/receiving end)If you need more cues than this, let us know, but reading the docs and/or Googling your way to how to do this will teach you more than a code-dump will.
Upvotes: 1