johnmk Posted April 14, 2011 Share Posted April 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233745-making-options-available-change-based-on-what-is-selected-from-dropdown-box/ Share on other sites More sharing options...
KevinM1 Posted April 14, 2011 Share Posted April 14, 2011 = is the assignment operator. == is the equality operator. Use == in if-conditionals. Quote Link to comment https://forums.phpfreaks.com/topic/233745-making-options-available-change-based-on-what-is-selected-from-dropdown-box/#findComment-1201692 Share on other sites More sharing options...
johnmk Posted April 14, 2011 Author Share Posted April 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233745-making-options-available-change-based-on-what-is-selected-from-dropdown-box/#findComment-1201695 Share on other sites More sharing options...
KevinM1 Posted April 14, 2011 Share Posted April 14, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/233745-making-options-available-change-based-on-what-is-selected-from-dropdown-box/#findComment-1201699 Share on other sites More sharing options...
johnmk Posted April 14, 2011 Author Share Posted April 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233745-making-options-available-change-based-on-what-is-selected-from-dropdown-box/#findComment-1201701 Share on other sites More sharing options...
johnmk Posted April 14, 2011 Author Share Posted April 14, 2011 Am I going about this the wrong way? I've tried to google a solution with no luck as I can't find anything similar enough to my situation to see how its done correctly. Quote Link to comment https://forums.phpfreaks.com/topic/233745-making-options-available-change-based-on-what-is-selected-from-dropdown-box/#findComment-1201719 Share on other sites More sharing options...
Psycho Posted April 14, 2011 Share Posted April 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233745-making-options-available-change-based-on-what-is-selected-from-dropdown-box/#findComment-1201733 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.