Jump to content

Add a new dropdown box if an option has been selected?


Cory94bailly

Recommended Posts

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.