Cory94bailly Posted May 31, 2008 Share Posted May 31, 2008 Example: I have a dropdown box named "Food" and if they choose let's say.. "Cake", I want it to show another dropdown box under it with the options of let's say... "Chocolate" and "Vanilla"... I know this is possible but idk how.. I have a feeling it's ajax but I've never used ajax before... Quote Link to comment https://forums.phpfreaks.com/topic/108166-add-a-new-dropdown-box-if-an-option-has-been-selected/ Share on other sites More sharing options...
haku Posted May 31, 2008 Share Posted May 31, 2008 You'd be correct in thinking its Ajax. Actually, it could be pure javascript if you don't have that many potential sets to be displayed based on the first selection, but if there are large numbers of possibilities, ajax is what you want. Quote Link to comment https://forums.phpfreaks.com/topic/108166-add-a-new-dropdown-box-if-an-option-has-been-selected/#findComment-554514 Share on other sites More sharing options...
.josh Posted June 1, 2008 Share Posted June 1, 2008 You'd be correct in thinking its Ajax. Actually, it could be pure javascript if you don't have that many potential sets to be displayed based on the first selection, but if there are large numbers of possibilities, ajax is what you want. You'll want to use ajax if you are wanting to retrieve the selections from a database or flatfile, which is what you will be wanting to do if you plan on wanting to change those selections from time to time for whatever reason. But if you don't plan on changing any of the selection choices, I'd stick with pure javascript, regardless of how many choice/subchoices. Quote Link to comment https://forums.phpfreaks.com/topic/108166-add-a-new-dropdown-box-if-an-option-has-been-selected/#findComment-554610 Share on other sites More sharing options...
haku Posted June 1, 2008 Share Posted June 1, 2008 If you have numerous potential menus that could pop up, loading them all at the start and using javascript to decide which one to make visible would be terribly inefficient, in which case ajax would be preferrable. Quote Link to comment https://forums.phpfreaks.com/topic/108166-add-a-new-dropdown-box-if-an-option-has-been-selected/#findComment-554657 Share on other sites More sharing options...
.josh Posted June 1, 2008 Share Posted June 1, 2008 I think you're making a mountain out of a molehill though. I'd agree if we're talking about thousands of choices in each box or something but people usually don't have anywhere near that many choices, so it's really not a big deal. Quote Link to comment https://forums.phpfreaks.com/topic/108166-add-a-new-dropdown-box-if-an-option-has-been-selected/#findComment-554827 Share on other sites More sharing options...
haku Posted June 1, 2008 Share Posted June 1, 2008 I'm just a purist - I really prefer to have as little extra markup on my page as possible. Quote Link to comment https://forums.phpfreaks.com/topic/108166-add-a-new-dropdown-box-if-an-option-has-been-selected/#findComment-554866 Share on other sites More sharing options...
Cory94bailly Posted June 1, 2008 Author Share Posted June 1, 2008 I think you guys are misinterpreting this... I want something exactly like I said.. No need for a DB, I want them to choose the stuff right there.. LIke if they choose one thing, another pops up.. Each will only have 2 or 3 options so I'm looking into javascript.. Quote Link to comment https://forums.phpfreaks.com/topic/108166-add-a-new-dropdown-box-if-an-option-has-been-selected/#findComment-554876 Share on other sites More sharing options...
.josh Posted June 1, 2008 Share Posted June 1, 2008 I'm just a purist - I really prefer to have as little extra markup on my page as possible. Well you can't be that much of a purist, suggesting ajax, such and all... I think you guys are misinterpreting this... I want something exactly like I said.. No need for a DB, I want them to choose the stuff right there.. LIke if they choose one thing, another pops up.. Each will only have 2 or 3 options so I'm looking into javascript.. Well, what you should be considering is that javascript can be turned off on the user's end, rendering your script useless. The same could be said about ajax. Quote Link to comment https://forums.phpfreaks.com/topic/108166-add-a-new-dropdown-box-if-an-option-has-been-selected/#findComment-554884 Share on other sites More sharing options...
haku Posted June 1, 2008 Share Posted June 1, 2008 Well you can't be that much of a purist, suggesting ajax, such and all... I use ajax extensively, but I only use unobtrusive javascripting so that my sites work entirely whether javascript is turned on or off. I work on the principle of javascript being for extra functionality, not core functionality. I think you guys are misinterpreting this... Where are we misinterpreting it? You gave a situation without explaining the number of choices that could exist. You were given different options depending on the number of choices. This apparently has been enough for you to realize what you need to do, which says to me that we didn't misinterpret it at all. No need for a DB, I want them to choose the stuff right there.. LIke if they choose one thing, another pops up.. Each will only have 2 or 3 options so I'm looking into javascript.. You definitely don't need ajax for this then. However, as crayon violent has said, you need to keep in mind that your users may have javascript turned off. In this case I would create a form with the first drop down menu visible, and the other drop down menus set to hidden. Then use javascript to show the necessary second drop down menu. However, on submit, I would check to see if any selection was made from that second drop down menu (which means you will want to make sure the default for all the second menus are an empty selection). If no selection has been made, then you should have the user directed to a page that displays only the appropriate second menu visible, and have the user make their second selection from there. Quote Link to comment https://forums.phpfreaks.com/topic/108166-add-a-new-dropdown-box-if-an-option-has-been-selected/#findComment-554893 Share on other sites More sharing options...
.josh Posted June 1, 2008 Share Posted June 1, 2008 I use ajax extensively, but I only use unobtrusive javascripting so that my sites work entirely whether javascript is turned on or off. I work on the principle of javascript being for extra functionality, not core functionality. Fair enough. Quote Link to comment https://forums.phpfreaks.com/topic/108166-add-a-new-dropdown-box-if-an-option-has-been-selected/#findComment-554895 Share on other sites More sharing options...
Cory94bailly Posted June 1, 2008 Author Share Posted June 1, 2008 Well I was thinking that if they don't have javascript enabled, just show a watered-down version of my script.. Quote Link to comment https://forums.phpfreaks.com/topic/108166-add-a-new-dropdown-box-if-an-option-has-been-selected/#findComment-554963 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.