Skip to content
Advertisement

populating text boxes using a drop down menu with database information

hello people I am currently pulling my hair out trying to figure out how to populate text boxes with the information in a database after the user has selected “date” for example from a dropdown menu.

My dropdown menu is currently being populated by the departure_date of a tour and I would like all of the other information connected to that date to be displayed into the text boxes on the page.

This is for a project I am working on and our current server does not support pdo unfortunately.

This is making my head spin and I cannot think about how I am supposed to accomplish this. Searching on the internet did not give me any useful information.

Here is my html code for the select box and text boxes.

JavaScript

and here is my php connection code

JavaScript

Any help would be great.

Advertisement

Answer

Ok, this question is asked and answered a lot and most of those who ask have a concept problem. I’ll explain this in parts, and afterwards I’ll post a clean rewrite of your code, including a javascript file for you to dive in and learn

  • The idea behind what you are trying to do involves some sort of behaviour on the part of what looks most likely to be a static html page
  • Javascript adds behaviour to your otherwise dead html, allowing you to trigger events and generate responses
  • Ajax was born out of a collective necessity to be able to talk to the server while the user did not leave the page. It allows us to make requests behind the scene (asynchronously) and bring back info
  • the power to combine behaviour with asynchronous requests is the base of today’s rich internet applications (RIA for short?)

Ok, don’t take that at face value, do some research on it and and you’ll find out the potential. In the meantime I’ll create a mockup of what it looks like you want and I’ll be back with it as soon as I can. Be on the lookout for other answers, there is a lot of knowledgeable people around ^^

edits

html form

JavaScript

javascript

lot’s of edits and rewrites. This is a noisy script with lots of alerts so please be patient and sequentially start removing alerts as you no longer need them. Attention: the select tag has an id that I use to find it and attach the event handler

JavaScript

ajax script, the php handler

JavaScript

There it is, it’s not tested and it’s a handfull but with careful review you will learn a LOT. Also read Crockford and take into consideration the benefits of using jQuery, that javascript could have been much less complicated, and more efficient with jQuery

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement