Populate query result to drop down list with Ajax - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Populate query result to drop down list with Ajax (/showthread.php?tid=9625) |
Populate query result to drop down list with Ajax - El Forum - 07-02-2008 [eluser]kuanfai[/eluser] Hi, I think this topic has been discussed before however I can't find the solution for my problem. There are two drop down list in my html form, the contents of "contest" drop down depends on the selected option from "store" drop down box. Code: <?php and my javascript for fetching 2nd list from DB: Code: [removed] The PHP codes which query the db: Code: function searchcontest ($storeid) { my problem is the returned $output is an array, how do I pass its value to the "contest" drop down list? (Only one column of the output needs to be populated to the "contest" drop down list.) Populate query result to drop down list with Ajax - El Forum - 07-02-2008 [eluser]Sumon[/eluser] Might be a solution: Write full drop down list in searchcontest () function. Function looks like: Code: function searchcontest ($storeid) { Populate query result to drop down list with Ajax - El Forum - 07-02-2008 [eluser]kuanfai[/eluser] Thanks Sumon. It does work. But is there any other way to do it? Populate query result to drop down list with Ajax - El Forum - 07-02-2008 [eluser]Sumon[/eluser] Ops there are one way in my mind to follow MVC for current situation. Code: // this is Modle function Called by controller Code: // Lets say contest_dropdown.php Populate query result to drop down list with Ajax - El Forum - 07-03-2008 [eluser]kuanfai[/eluser] Hi Sumon, appreciate your help. I have also figured out how to solve this problem with the following changes to the controller and [removed] Code: function searchcontest ($storeid) { and Code: function setOutput(){ Cheers! Populate query result to drop down list with Ajax - El Forum - 07-03-2008 [eluser]Bramme[/eluser] You should have a look at JSON. This was specifically designed for this type of thing. I don't know how to handle it in raw javascript, but I know jquery supports it. Basically you echo your array like you would echo html, only you use the json structure (I believe you have to set a header too), you get that result through your ajax call and then jquery can process that json array. |