How to set value in the dropdown from a JSON data list?

AJAX: I want to set an initial value for a combo box, then have a dropdown list of other values. How can I do that?

  • I want to have a combo box and set an initial value for it. But I still want the user to be able to click to see a dropdown list of options that are different from the initial value. An example of what I have in mind is the public transportation direction of Google Maps (http://maps.google.com/maps?f=d&source=s_d&saddr=&daddr=Harvard+Square%2C+Cambridge%2C+MA+02138&hl=en&geocode=&mra=ls&dirflg=r&ttype=dep&date=04%2F01%2F11&time=12%3A55am&noexp=0&noal=0&sort=def&sll=42.328403%2C-71.107302&sspn=0.011945%2C0.01929&ie=UTF8&start=0&z=16). You can see that in the rightmost combo box, the initial value is set at the current time. But the user can still click on the arrow and see a dropdown list of values that are different from the initial value. I've looked at FlexBox (http://www.fairwaytech.com/flexbox) but whenever I set an initial value, only that initial value is present in the dropdown list. You can see that in this demo #7 (http://www.fairwaytech.com/flexbox/flexbox-demos.aspx#demo7). Is there any way to configure FlexBox to do what I need? Or is there another combo box I can use? What does Google use for their Google Maps combo box? Thanks.

  • Answer:

    I've never used FlexBox, but I can take a shot in the dark from what I see in the docs. It looks like the arrow key doesn't do quite what it seems toĆ¢€”there's a configuration setting called arrowQuery which controls the query sent to the server when you click the arrow, so I'd guess the box doesn't actually have any data (besides the default value you're adding) until some kind of query fills it with results. If that's true, you could set up a small script on your server that just returns the data you want every box to have and configure the arrowQuery setting to call it. If all you want is a combo box with a dynamic default value, I'd say FlexBox is a lot more power than you need. In that case I'd just write an HTML select with an empty <option selected="selected"> (or add one at runtime) and fill it with the default when the page is ready.

Bulat Bochkariov at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.