Jump to content

Variable for drop down value


mtgriffiths

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.