Luthando Ntsekwa
Luthando Ntsekwa

Reputation: 4218

Displaying the most selected items first

Is there any way I can display the most selected items first in a drop-down?

E.g I have a drop-down which is loaded with 6 items when the application loads:


Lets say the user selects item-C and submits the form.
When the user comes back to this form, I want to sort the dropdown by the most selected items, So in this case the dropdown would be like this:

Is there any jquery plugin that can do this? or do I need to have a table in my database that will store the most selected items?(this would be my last resort)

Upvotes: 1

Views: 83

Answers (1)

dust
dust

Reputation: 512

You did not specify whether you want any user to see the frequency of responses by all users, or to have the same user always see the answers he/she selected most often.

If you want the former, you need some persistence on server side, e.g. very simple database (two columns: selectedOption, howManyTimesSelected). Even storing in a file would do, but you should then provide some way of securing against race condition (e.g. allow the file to be open for writing by one instance only).

If you want the latter, you can store that information in a cookie on client's side.

Upvotes: 1

Related Questions