Is this Possible with PHP alone?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nathanbrooks
Forum Newbie
Posts: 8
Joined: Tue Aug 18, 2009 10:59 am

Is this Possible with PHP alone?

Post by nathanbrooks »

Hi there,

Was wondering if the following is possible to do with PHP alone and nothing else.

Is it possible to have one drop-down menu with which you must select the nation you live in, and once you have selected a nation, without pressing anything, a drop-down menu pops up with a selection of provinces/states for you to select.

So in otherwords the second drop down menu only pops up once you click on a country on the previous drop down.

Hope I am making sense here.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Is this Possible with PHP alone?

Post by papa »

Just use onclick submit on your dropdown.

If that var is set, show the next dropdown with appropriate data.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Is this Possible with PHP alone?

Post by Eran »

I think he meant without page refresh so submitting would probably not be a good idea.

As to the OP original question - This can be achieved using client-side technologies only, namely Javascript.
nathanbrooks
Forum Newbie
Posts: 8
Joined: Tue Aug 18, 2009 10:59 am

Re: Is this Possible with PHP alone?

Post by nathanbrooks »

Thanks pytrin that is exactly what I was talking about.

I suppose that Ajax is way beyond me at the moment so I don't want to get into it unless it is absolutely necessary. How tricky would it be to do it with javascript?

Any links or suggestions as to where I can get some help on this?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Is this Possible with PHP alone?

Post by Eran »

One approach is to have all the information available on the page, with some of it hidden. You can then show/hide information as the user changes his selection. Take a look at the following example - http://blog.movalog.com/a/javascript-toggle-visibility/
If you want to retrieve dynamic information from the server (for example, something that is stored in files or a database), you would have to use AJAX techniques.

You can try one of the available Javascript frameworks, such as jQuery ExtJs and others. They make those common operations very easy to implement (including ajax).
Post Reply