Results 1 to 3 of 3

Thread: javascript, php, sql, and dynamicly generated listboxes

  1. #1
    Join Date
    Jan 2011

    javascript, php, sql, and dynamicly generated listboxes


    I hope i have posted this in the right place

    I want to dynamically generate list box options using the content of an sql database in real time. More specifically, i have a page with a couple of listboxes, when i click on an option in the first list box, i want the second list box to update with options that reflect the first one, in real time generated by the sql database.

    now i was wondering if it might be possible for javascript to send some thing to php which php could decode and search the database and return the results of that search. here is how i imagine the process to look in psudeo code:

    - user clicks on an option (say the 3rd option) in the 1st listbox
    - javascript catches the event, and sends some data to php indicating the 3rd option from the 1st listbox has been clicked
    - php tells sql to search for records that correlate with the 3rd option from listbox 1
    - php sends search result back to javascript
    - javascript populates the 2nd listbox with search results

    i want to do this with out having to refresh the webpage, security issues aint high, cause this project probably aint gonna go on the web. I got the idea from the dynamic searching on google, so i guess such technology is possible some how.

    If anybody could help me out i would greatly appriciate it, cause atm i'm at a bit of an in pass, and not sure what direction to proceed.


  2. #2
    Join Date
    Mar 2010
    You can use AJAX to do all that, but it won't work in javscript disabled browsers.

    1) put an onchange event on the 1st select list that sends the selected value to a php script, via ajax, to retrieve the records from the database for the selected value.

    2) the php script then generates the html for the options in the 2nd select list using the retrieved records.

    3) the php generated html is then returned to the ajax function.

    4) the ajax function then replaces the html for any options in the 2nd select list with the new html just received.

  3. #3
    Join Date
    Jan 2011
    thanks for your reply! i will take a look at that tommorow, and will report back to let you know how i got on


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles