mtgriffiths Posted March 5, 2008 Share Posted March 5, 2008 Hey All, What i am trying to do is to create a variable containing the value of a previously selected text box. The second text box is dynamically populated depending on a league. The first text box is to choose the league 1-3 I want to capture the value 1,2 or 3 so that when my query for my dynamic box is run is can do something like: WHERE League = $Variable Is this possible? Thanks in advance Matthew Quote Link to comment https://forums.phpfreaks.com/topic/94468-variable-for-drop-down-value/ Share on other sites More sharing options...
redarrow Posted March 5, 2008 Share Posted March 5, 2008 use sessions mate look it up............ remember <?php session_start(); ?> must go on all pages that use sessions....... Quote Link to comment https://forums.phpfreaks.com/topic/94468-variable-for-drop-down-value/#findComment-483754 Share on other sites More sharing options...
mtgriffiths Posted March 5, 2008 Author Share Posted March 5, 2008 Thanks for such a quick reply. I have touched upon sessions in the past but i cant see how it would work here...my lack of experience im guessing. Could you point my in what direction of sessions i should be looking in please? Thanks again Matthew Quote Link to comment https://forums.phpfreaks.com/topic/94468-variable-for-drop-down-value/#findComment-483776 Share on other sites More sharing options...
haku Posted March 5, 2008 Share Posted March 5, 2008 I have no idea why you would need sessions for this either. What do you mean by 'populated dynamically'? Do you want to load it after a page refresh, or right away after the value has been selected from the drop down menu? Quote Link to comment https://forums.phpfreaks.com/topic/94468-variable-for-drop-down-value/#findComment-483787 Share on other sites More sharing options...
mtgriffiths Posted March 5, 2008 Author Share Posted March 5, 2008 Well the drop down menu is populated by the teams names in the database. The query that i am currently using is: select * from team_details WHERE League = 1" I would like to change it to something like: "select * from team_details WHERE League = $drop_down_value" The drop down value would be 1, 2 or 3 so depending on the choice the correct teams will be shown Hope that helps Matthew Quote Link to comment https://forums.phpfreaks.com/topic/94468-variable-for-drop-down-value/#findComment-483821 Share on other sites More sharing options...
haku Posted March 5, 2008 Share Posted March 5, 2008 That will pretty much work. You have set $drop_down_value first though. $drop_down_value =$_POST['drop_down_menu_name']; Quote Link to comment https://forums.phpfreaks.com/topic/94468-variable-for-drop-down-value/#findComment-483826 Share on other sites More sharing options...
mtgriffiths Posted March 5, 2008 Author Share Posted March 5, 2008 The 2 drop down menus are on the same page. Would the page have to refresh to do this or isit possible to do it real time? Quote Link to comment https://forums.phpfreaks.com/topic/94468-variable-for-drop-down-value/#findComment-483831 Share on other sites More sharing options...
mtgriffiths Posted March 5, 2008 Author Share Posted March 5, 2008 Hi again, I have been looking at submitting the form to the same page so that i can get the variable. Once i click on the league i want from the drop down menu the page submits to itself so that the variable can be worked out. Im unsure on how i can do this tho. Can anyone point me in the right direction please? Thanks in advance Matthew Quote Link to comment https://forums.phpfreaks.com/topic/94468-variable-for-drop-down-value/#findComment-483918 Share on other sites More sharing options...
haku Posted March 5, 2008 Share Posted March 5, 2008 Its possible to do this without a page re-load, but its not a php issue, its Ajax (a style of javascript). There is an ajax section on the top page if you want to check that out. But, its hard to implement, although there are pre-written scripts out there that can help you with this. Also, some people have javascript turned off, so you should build it to work in PHP first, and then add javascript afterwards if you want. To do it in php, what you do is make a form with the first drop down box in it. Set the action of the form to be the same as the name of the page that the form is on. Give the submit button a 'name' attribute. Then, at the top of that page, check to see if the $_POST with that name is set. If it is set, then pull out the correct results out of the database, and use them to create the second drop down menu. One thing I should mention is that you shouldn't rebuild the original drop down menu here. If you do that, people will have to reload the page to get the new drop down results. Instead, output the value of the original selection as text, and then add a back button. Quote Link to comment https://forums.phpfreaks.com/topic/94468-variable-for-drop-down-value/#findComment-483992 Share on other sites More sharing options...
soycharliente Posted March 5, 2008 Share Posted March 5, 2008 AJAX would work for doing it without reloading the page. The one way I can think of doing it with reloading the page is to have hidden fields at the bottom of your form. One for every drop down. Just show one drop down at a time. Check to see if it's hidden field is set to something when it's posting and you'll know whether or not to display the next one. Once they selecting something for each one, put that in it's hidden field so it keeps reposting it. Quote Link to comment https://forums.phpfreaks.com/topic/94468-variable-for-drop-down-value/#findComment-483998 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.