[PHP-DB] Automatic Listboxes
Hi there everyone, Hope you are all having a good new year :-) I have a problem, I am working on a search engine for a Travel Agents and before you get to the actual type-in search field, you have to select from 3 pulldowns. The first pulldown is country, then the second should popuplate from whichever country is selected and so on. My question is this: How can I populate a pulldown box in a form from a DB automatically? In other words, what I need is once they have selected the first listbox, instead of having to click GO to populate the second one it does it automatically after selecting the entry in the first box and so on. Can anyone help? Thank you all so much :-) Regards Chris Payne www.planetoxygene.com
Re: [PHP-DB] Automatic Listboxes
You'll have to submit the data. Just that instead of pushing go, you can get JavaScript to do that. For instance, form name=myForm1 action=? echo $PHP_SELF? select name=country onChange=document.myForm1.submit() option value=Albania option value=Andorra /select /form form name=myForm2 action=? echo $PHP_SELF? select name=country onChange=document.myForm2.submit() option value=Albania option value=Andorra /select /form form name=FinalForm action=final_URL select name=country option value=Albania option value=Andorra /select input type=submit /form You'll then have to check whether you have any field empty and, if so, echo the same form again, with the empty element populated. The final form actually contains the button which gets to the final page. Alternatively you could use a single form, but then you'll have both pieces of code (echoing the form and echoing the final page) in the same PHP - easily solvable with include() for clean coding. HTH Bogdan Chris Payne wrote: Hi there everyone, Hope you are all having a good new year :-) I have a problem, I am working on a search engine for a Travel Agents and before you get to the actual type-in search field, you have to select from 3 pulldowns. The first pulldown is country, then the second should popuplate from whichever country is selected and so on. My question is this: How can I populate a pulldown box in a form from a DB automatically? In other words, what I need is once they have selected the first listbox, instead of having to click GO to populate the second one it does it automatically after selecting the entry in the first box and so on. Can anyone help? Thank you all so much :-) Regards Chris Payne www.planetoxygene.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Automatic Listboxes
Javascript is your way to do this, but there are obviously a few ways you can do that aswell. You don't want to have to submit a form and reload images/pages etc, so javascript is the only way to go (or dhtml or other stuff) One way to do this is either with layers (hide/unhide depending on what need) and all the information is already printed to the page, but shows only the needed information. Another way is to create javascript arrays and let javascript do the selections and stuff... I've seen a few tutorials around that do that... Here are some links that might help you: This is for dreamweaver and ASP but same principal (and explains how it works aswell) http://www.macromedia.com/support/ultradev/ts/documents/client_dynamic_listb ox.htm This is something similar, and also cool... http://javascript.internet.com/forms/auto-drop-down.html This is a basically what you want... but you might have to modify it a little bit... http://javascript.internet.com/forms/category-selection.html So you get PHP to fill the javascript array by something like this, knowing that I am no genius in javascript (as long as you have values in $array): head script langauage=Javascript !-- function start(){ var something = new Array(); ?php for ($i=0;$icount($array);$i++){ echo javascript array stuff -- $array[$i]; } ? // now the other javascript code (additional lists etc) } and then thats it! (well, sorta, but you get the jist) Adam -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]