This is a discussion on "Linking Dropdown boxes" within the PHP Forum section. This forum, and the thread "Linking Dropdown boxes are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Linking Dropdown boxes
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
Linking Dropdown boxes
Hi All,
I am pulling my hair out trying to link to drop downs together. Both dropdowns are populated from a mySQL database. I know I need to use AJAX to do this but i cannot work it out. Here is my code!
Can anyone help me? |
|
|
|
#2
|
|||
|
|||
|
Re: Linking Dropdown boxes
This is obviously only part of your code as the form elements are not all here.
You don't necessarily need to get into AJAX if you don't want to. All the php code in your page is going to get parsed each time the page is loaded. If you have the 'action' attribute of the form element set to '' then each time the form is submitted, the page will reload. What you have to control is which bits of information are 'sticky', that is held over from the previous parsing of the form and which bits of information are new based on certain values passed when the form was submitted. |
|
#3
|
|||
|
|||
|
Re: Linking Dropdown boxes
i dont want to submit all the time because it submits to a database so i only want to make a submission once. I want it to work like on the insurance sites where you select manufacturer and then the next drop down will be filled with only cars from that manufacturer!
|
|
#4
|
|||
|
|||
|
Re: Linking Dropdown boxes
How complex and how many options are involved?
|
|
#5
|
|||
|
|||
|
Re: Linking Dropdown boxes
Well my page is for an Equipment Database for work.
So there is a field for "Site" as you have seen, there are only 4 sites in total. Then each site has several departments, so there is a department field. Both of these fields are filled in from two separate tables in my database! The query runs on site ID which is the value that will be passed through from the site options when selected. I simply need to know how to get the value that is passed through, i have managed to get as far as displaying it in an alert, but i need to extract the site number and then pass that through to the other drop down so that the query is correct! |
|
#6
|
|||
|
|||
|
Re: Linking Dropdown boxes
Is it viable to have the possible variation loaded into the page but hidden and selected as required or is there too much data?
|
|
#7
|
|||
|
|||
|
Re: Linking Dropdown boxes
The problem is that we are expanding so while there isnt much data at the moment, within the next year there maybe!
|
|
#8
|
||||
|
||||
|
Re: Linking Dropdown boxes
You don't need Ajax. The code would be complicated-looking but should be conceptually simple -- you could do it by nesting "if" clauses, maybe in "switch" format for better transparency.
This might be easier to keep track of by using a different pages and putting the "if" handlers in the action section of the form, since you'll have to reload anyway, depending on how fast your pages load. Keep it light on graphics or preload. Subsequent pages should load in less than a second if you keep the heavy html in the includes. Of course, Ajax is a lot slicker. As far as Ajax goes, this would be comparatively simple. But remember, some visitors will have javascript disabled and you might want a php backup anyway. Another thought is to use css and unhide the subsequent menus. That would have the advantage of being cool. I wouldn't be able to resist the temptation of restyling the page a little depending on the choice, though. Last edited by masonbarge; Oct 29th, 2006 at 18:23. Reason: misspelling |
|
#9
|
|||
|
|||
|
Re: Linking Dropdown boxes
So your suggesting that i just use PHP and dont bother with AJAX?
As far as i understood you could not do it in PHP as you have to submit the page to retrieve the second SQL query and when you submit the page you will then be writing to the database. Am i missing something here? is it possible to submit a PHP page without actually doing the final submit? |
|
#10
|
|||
|
|||
|
Re: Linking Dropdown boxes
Yes. You control the value of the submit button so that it only has a valid value when the submit button itself is pressed.
You check for this when the page is parsed and only write to the database if its valid. |
|
#11
|
|||
|
|||
|
Re: Linking Dropdown boxes
OK i think i get it!
So if i set the value of the Submit button to something like "Process" and then i submit the form after selecting the first dropdown it will not post to the database because i will have an if statement that will only become active when process is pressed! Am i correct? |
|
#12
|
||||
|
||||
|
Re: Linking Dropdown boxes
What you're talking about is easier than it sounds. You seem to be locked into thinking that you are going to have one form with a lot of submit buttons doing different things. The easiest way to do this, however, is to have three (or however many) forms. All the first two do is pass variable values to the final one.
I am actually working on a complex three-page form. It's fully functional but not styled -- in IE the elements don't even have initial alignment so use Firefox if you can: http://www.dhreport.com/articles/foo...h_nutrient.php Check "yes" to the last question if you want to see the second page. This actually performs like the one you want, only the second version of the second form is just a check button rather than a different version of form #2. If you check "yes" on page one, the second page stores the variables from the first page and adds other variables. Try drafting this with a different page for each form, a single form on each page. When you have that working it will be a lot clearer how to structure it. As far as AJAX, I'd do the php first, because it is (by its nature) 100% functional cross-browser. I'd never say "don't bother with AJAX' -- it's just too cool. |
|
#13
|
|||
|
|||
|
Re: Linking Dropdown boxes
OK i finally got it working using javascript to submit the form on change and using Sticky Forms
Thanks for all your help |
![]() |
| Tags |
| php ajax |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need Help with this Dropdown Content | Maska | JavaScript Forum | 7 | Sep 21st, 2007 16:44 |
| menu, dropdown | everland | Flash & Multimedia Forum | 2 | Aug 21st, 2007 14:58 |
| Dropdown lists | psrujan | JavaScript Forum | 1 | Jun 30th, 2007 22:37 |
| Dropdown Problem | leewad | JavaScript Forum | 1 | Jul 27th, 2006 21:51 |
| Dropdown menu | Jorgerb | Flash & Multimedia Forum | 6 | May 17th, 2005 08:29 |