How do I filter a combo boxes values based on a value selected in a previous combo box?

How do I filter a combo boxes values based on a value selected in a previous combo box?

Andrew_whiteAndrew_white Posts: 4Questions: 2Answers: 0

I have a situation where I need to be able to filter a secondary combo boxes values, based on a value selected from a previous combo box. I am very new to this coding thing and have been told of an ajax solution, but am finding it difficult to implement in practice. My example is based on a gold courses and their associated tee boxes.

So when a golf course is selected from the first combo box, the second combo must only display tee boxes linked to that golf course. This is to take place in the form displayed when updating a record. Any help in this regard would be greatly appreciated.

'golfcourses' is a table in the database and 'teeboxes' is the linked table in the database. golfcourses.Id is the primary key on the golfcourses table and the foreign key on the teeboxes table.

Any help will be greatly appreciated.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 64,899Questions: 1Answers: 10,747 Site admin
    Answer ✓

    Hi Andrew,

    It sounds like the dependent() method might be what you want here. It can appear a little complicated on first use, but basically it will make an Ajax call to the server when the golf value is changed. Then you need to have a script on the server that will accept that request and return the tees specific to that golf course (this is not something that is provided by the PHP or .NET libraries for Editor). The response from that script will define the options for the tees and they will be updated.

    So on the client-side you only really need a one liner with dependent(). The key is to write the server-side script that will get the options from the database with a little SQL query.

    Allan

  • Andrew_whiteAndrew_white Posts: 4Questions: 2Answers: 0

    Thanks Allan! I will give it a try ... PS loving these Datatables !!

This discussion has been closed.