Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have a json file set as this:
{"John":"john@email.com","Mary":"mary@email.com","Andrew":"andrew@mail.com"}

obviusly this is an example list, actual one is much longer.

I'm trying to build a combobox in an HTML page that shows the names of the poeple and, when a name is selected, it pass the email as variable to a PHP script.

Any idea how to do it?
Posted
Updated 12-May-15 5:43am
v3
Comments
Sergey Alexandrovich Kryukov 12-May-15 11:37am    
Ideas?! Just do it. What do you want to put in the list, exactly? Do you want to generate the content on server side or client side? What's the problem?
—SA

1 solution

If you want to generate content on the server side and have JSON string only, not the PHP structure, you can obtain it using json_decode:
http://php.net/manual/en/function.json-decode.php[^].

It's also possible that you have this string or corresponding JavaScript object on client side. If you have the object with the properties you mentioned in your example, you don't need JSON, just directly populate the data in DOM. If you only have the JSON string, use native JavaScript JSON object:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON[^],
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900