Jump to content

Making options available change based on what is selected from dropdown box


Recommended Posts

I'm new to this form and php/mysql so sorry if this isn't the right place to post this.

 

 

This is what is in the first dropdown box.

 
$selValues['john'] = "a, b, c, d, e";

 

These are the different lists I want it to put in the second drop down box depending on what they choose in the first.

$selValues['list1']= " a1, a2, a3, a4, a5";
$selValues['list2']= " b1, b2, b3, b4, b5";

 

This is how I made an attempt to make it work before posting here. Along with plently of other ways.

if ($selValues['john']=a)
{
     $chan_input = selectBuilder($selValues['$list1'] };
else if ($selValues['john']=b)
{
     $chan_input = selectBuilder($selValues['$list2'] };

 

Basicly how I need it to work is there are two drop down boxes. First they will chose between a,b,c,d,e. If they chose a then on the second drop down box I only want them to be able to select a1,a2,a3,a4,a5.

I did try that before but didn't get the right results.

But before I go on this is what you wanted me to change, correct?

if ($selValues['john']=a)
{
     $chan_input == selectBuilder($selValues['$list1'] };
else if ($selValues['john']=b)
{
     $chan_input == selectBuilder($selValues['$list2'] };

or

 

if ($selValues['john']==a)
{
     $chan_input = selectBuilder($selValues['$list1'] };
else if ($selValues['john']==b)
{
     $chan_input = selectBuilder($selValues['$list2'] };

 

What happens when I try that is it will always pull the list for a, since it's the first one in the code. If I swap around a and b then it always displays b since it's first.

The reason is (at least I think why) is that 

 $selValues['john']= "a, b, c, d, e"; 

just puts all of them in there as if they were together, not seperate.

So it will always be the first one I put in the list, as it will always be true.

 

I think you need to take a step back and describe what you want your data to be.  Right now, you have an array - $selValues - with one element.  The element index is 'john' and the element contains 'a, b, c, d, e'.  Is that what you want?

As I said before, i'm new to this. I understand what you are asking but not sure how to answer based on the knowledge I have right now.

 

      Basically how I need it to work is like this. There are two drop down boxes, lets just say they both start off blank. When you scroll through the first

one you see different options like a, b, c, d, e. If you choose a then in the second drop down box there will be a1, a2, a3, a4, a5. If you chose d in the first

dropdown box then in the second you will only see d1, d2, d3, d4, d5.

If you want this to happen in real-time (i.e as soon as the user makes a change in the first select box the options in the 2nd immediately change) then you need to use JavaScript (possibly with a PHP back-end script). If you want just a PHP solution then you will have to make the user make a selecting in the first select list and then submit the page before getting the revised list in the 2nd select box.

 

Are you really wanting the options a1, a2, a3, etc. or are those just examples of what you are trying to achieve. If the values you displayed above are really the values you are going to use, then a JS only solution would be simple to implement. But, on second thought why do you need to do this at all? Just have one select list for the user to select the letter and the second to select the number. Then on the receiving page you can combine the two to get the resulting value.

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.