Welcome! Log In Create A New Profile

Advanced

[PHP] Creating drop-down menus

Posted by Ramiro Barrantes 
Ramiro Barrantes
[PHP] Creating drop-down menus
July 16, 2012 10:20PM
Hello,

I am making an application using PHP/Javascript/mysql and had a question.

Sometimes I need to use javascript to fill a drop down box based on the value of a previous drop down box. However, the information to fill the latter is stored in mysql and can be a lot, what I have been doing is that, using PHP, I create hidden fields with all the possible information that might be needed to fill the second drop down.

For example, the user chooses a bank from a drop down, and then a list of clients is displayed on the following drop down. I use PHP to read all clients from all the banks and put that as hidden fields on the html page. It is very cumbersome.

I do not want to read the database (which changes dynamically) from javascript directly due to confidentiality and because a lot of care has been taken to create the appropriate queries with checks and protect misuse of the information using PHP.

My questions are:
1) Do people just normally use hidden fields to store possible information to fill the drop downs?
2) any suggestions?

Thanks in advance,
Ramiro
Jen Rasmussen
RE: [PHP] Creating drop-down menus
July 16, 2012 10:20PM
-----Original Message-----
From: Ramiro Barrantes [mailto:[email protected]]
Sent: Monday, July 16, 2012 3:17 PM
To: php-general@lists.php.net
Subject: [PHP] Creating drop-down menus

Hello,

I am making an application using PHP/Javascript/mysql and had a question.

Sometimes I need to use javascript to fill a drop down box based on the
value of a previous drop down box. However, the information to fill the
latter is stored in mysql and can be a lot, what I have been doing is that,
using PHP, I create hidden fields with all the possible information that
might be needed to fill the second drop down.

For example, the user chooses a bank from a drop down, and then a list of
clients is displayed on the following drop down. I use PHP to read all
clients from all the banks and put that as hidden fields on the html page.
It is very cumbersome.

I do not want to read the database (which changes dynamically) from
javascript directly due to confidentiality and because a lot of care has
been taken to create the appropriate queries with checks and protect misuse
of the information using PHP.

My questions are:
1) Do people just normally use hidden fields to store possible information
to fill the drop downs?
2) any suggestions?

Thanks in advance,
Ramiro

**

You could also store the information as a session variable.

Jen




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Tim Streater
Re: [PHP] Creating drop-down menus
July 16, 2012 10:50PM
On 16 Jul 2012 at 21:19, Jen Rasmussen <[email protected]> wrote:

> Sometimes I need to use javascript to fill a drop down box based on the
> value of a previous drop down box. However, the information to fill the
> latter is stored in mysql and can be a lot, what I have been doing is that,
> using PHP, I create hidden fields with all the possible information that
> might be needed to fill the second drop down.
>
> For example, the user chooses a bank from a drop down, and then a list of
> clients is displayed on the following drop down. I use PHP to read all
> clients from all the banks and put that as hidden fields on the html page.
> It is very cumbersome.

Well it would be. This approach doesn't scale.

> I do not want to read the database (which changes dynamically) from
> javascript directly due to confidentiality and because a lot of care has
> been taken to create the appropriate queries with checks and protect misuse
> of the information using PHP.

I doubt if you can read it from JavaScript.

> My questions are:
> 1) Do people just normally use hidden fields to store possible information
> to fill the drop downs?
> 2) any suggestions?

You could use ajax to request the information needed to load the second drop down. Once the user chooses their bank, then your JavaScript makes an ajax request to a PHP script that returns the clients list. You use this to populate the second drop down.

--
Cheers -- Tim

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Daevid Vincent
RE: [PHP] Creating drop-down menus
July 16, 2012 11:30PM
AJAX.

Your page calls a PHP 'ajax' routine that pulls the data, sends it back as a
JS array, and you re-populate the second select box. Welcome to the year
2000. Using frameworks like jQuery, this is pretty trivial these days.
You're not trading any security since the PHP gets whatever parameters and
checks whatever $_SESSION or other authentication and only sends back
whatever data is needed. You can add some caching (memcached or whatever
else) to make subsequent calls lightning fast.

> -----Original Message-----
> From: Ramiro Barrantes [mailto:[email protected]]
> Sent: Monday, July 16, 2012 1:17 PM
> To: php-general@lists.php.net
> Subject: [PHP] Creating drop-down menus
>
> Hello,
>
> I am making an application using PHP/Javascript/mysql and had a question.
>
> Sometimes I need to use javascript to fill a drop down box based on the
> value of a previous drop down box. However, the information to fill the
> latter is stored in mysql and can be a lot, what I have been doing is
that,
> using PHP, I create hidden fields with all the possible information that
> might be needed to fill the second drop down.
>
> For example, the user chooses a bank from a drop down, and then a list of
> clients is displayed on the following drop down. I use PHP to read all
> clients from all the banks and put that as hidden fields on the html page.
> It is very cumbersome.
>
> I do not want to read the database (which changes dynamically) from
> javascript directly due to confidentiality and because a lot of care has
> been taken to create the appropriate queries with checks and protect
misuse
> of the information using PHP.
>
> My questions are:
> 1) Do people just normally use hidden fields to store possible information
> to fill the drop downs?
> 2) any suggestions?
>
> Thanks in advance,
> Ramiro



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Ramiro Barrantes
RE: [PHP] Creating drop-down menus
July 17, 2012 04:10PM
Thanks to everyone for their help, AJAX is the way to go.

Daevid, it's interesting you welcome me to the year 2000, I actually graduated from CS in 1999 and haven't really done much more than simple web-programming since (have done scientific programming instead), so I am definitely behind the times!!!

________________________________________
From: Jen Rasmussen [[email protected]]
Sent: Monday, July 16, 2012 4:19 PM
To: Ramiro Barrantes; php-general@lists.php.net
Subject: RE: [PHP] Creating drop-down menus

-----Original Message-----
From: Ramiro Barrantes [mailto:[email protected]]
Sent: Monday, July 16, 2012 3:17 PM
To: php-general@lists.php.net
Subject: [PHP] Creating drop-down menus

Hello,

I am making an application using PHP/Javascript/mysql and had a question.

Sometimes I need to use javascript to fill a drop down box based on the
value of a previous drop down box. However, the information to fill the
latter is stored in mysql and can be a lot, what I have been doing is that,
using PHP, I create hidden fields with all the possible information that
might be needed to fill the second drop down.

For example, the user chooses a bank from a drop down, and then a list of
clients is displayed on the following drop down. I use PHP to read all
clients from all the banks and put that as hidden fields on the html page.
It is very cumbersome.

I do not want to read the database (which changes dynamically) from
javascript directly due to confidentiality and because a lot of care has
been taken to create the appropriate queries with checks and protect misuse
of the information using PHP.

My questions are:
1) Do people just normally use hidden fields to store possible information
to fill the drop downs?
2) any suggestions?

Thanks in advance,
Ramiro

**

You could also store the information as a session variable.

Jen




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
James Newman
Re: [PHP] Creating drop-down menus
July 17, 2012 10:50PM
Just to put my 2cents in, you might want to try jQuery if you're going to
go down the AJAX road.

James.

On Wed, Jul 18, 2012 at 1:59 AM, Ramiro Barrantes <
[email protected]> wrote:

> Thanks to everyone for their help, AJAX is the way to go.
>
> Daevid, it's interesting you welcome me to the year 2000, I actually
> graduated from CS in 1999 and haven't really done much more than simple
> web-programming since (have done scientific programming instead), so I am
> definitely behind the times!!!
>
> ________________________________________
> From: Jen Rasmussen [[email protected]]
> Sent: Monday, July 16, 2012 4:19 PM
> To: Ramiro Barrantes; php-general@lists.php.net
> Subject: RE: [PHP] Creating drop-down menus
>
> -----Original Message-----
> From: Ramiro Barrantes [mailto:[email protected]]
> Sent: Monday, July 16, 2012 3:17 PM
> To: php-general@lists.php.net
> Subject: [PHP] Creating drop-down menus
>
> Hello,
>
> I am making an application using PHP/Javascript/mysql and had a question.
>
> Sometimes I need to use javascript to fill a drop down box based on the
> value of a previous drop down box. However, the information to fill the
> latter is stored in mysql and can be a lot, what I have been doing is that,
> using PHP, I create hidden fields with all the possible information that
> might be needed to fill the second drop down.
>
> For example, the user chooses a bank from a drop down, and then a list of
> clients is displayed on the following drop down. I use PHP to read all
> clients from all the banks and put that as hidden fields on the html page.
> It is very cumbersome.
>
> I do not want to read the database (which changes dynamically) from
> javascript directly due to confidentiality and because a lot of care has
> been taken to create the appropriate queries with checks and protect
> misuse
> of the information using PHP.
>
> My questions are:
> 1) Do people just normally use hidden fields to store possible information
> to fill the drop downs?
> 2) any suggestions?
>
> Thanks in advance,
> Ramiro
>
> **
>
> You could also store the information as a session variable.
>
> Jen
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Paul M Foster
Re: [PHP] Creating drop-down menus
July 17, 2012 11:00PM
On Wed, Jul 18, 2012 at 08:45:34AM +1200, James Newman wrote:

> Just to put my 2cents in, you might want to try jQuery if you're going to
> go down the AJAX road.

JQuery is a LOT of code to include if you're just going to do an AJAX
call or two. There are examples of doing straight AJAX with Javascript
on the 'Net. Once you work through them, you find that there's a
"static" part that you can include in all the files you want to make
AJAX calls. And then there's the part that deals directly with the data
you get back from whatever PHP or other script is feeding you data from
outside the website. That's the part that needs custom work. I *hate*
Javascript, but I managed to figure it out.

Another point: I'm not sure if it's the same for other people. I'm on a
crappy little computer running Linux. I've got a little CPU meter in my
taskbar. And nothing jacks that meter up like Javascript. I don't know
why, but Javascript just devours CPU on my computer. The more
javascript, the worse. And like I said, JQuery is a LOT of code. This is
one of the reasons I tend to code things in PHP instead of Javascript.

Paul

--
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Andrew Ballard
Re: [PHP] Creating drop-down menus
July 17, 2012 11:20PM
On Tue, Jul 17, 2012 at 4:58 PM, Paul M Foster <[email protected]> wrote:
> On Wed, Jul 18, 2012 at 08:45:34AM +1200, James Newman wrote:
>
>> Just to put my 2cents in, you might want to try jQuery if you're going to
>> go down the AJAX road.
>
> JQuery is a LOT of code to include if you're just going to do an AJAX
> call or two. There are examples of doing straight AJAX with Javascript
> on the 'Net. Once you work through them, you find that there's a
> "static" part that you can include in all the files you want to make
> AJAX calls. And then there's the part that deals directly with the data
> you get back from whatever PHP or other script is feeding you data from
> outside the website. That's the part that needs custom work. I *hate*
> Javascript, but I managed to figure it out.
>
> Another point: I'm not sure if it's the same for other people. I'm on a
> crappy little computer running Linux. I've got a little CPU meter in my
> taskbar. And nothing jacks that meter up like Javascript. I don't know
> why, but Javascript just devours CPU on my computer. The more
> javascript, the worse. And like I said, JQuery is a LOT of code. This is
> one of the reasons I tend to code things in PHP instead of Javascript.
>
> Paul
>

I found some time ago that a lot of those simple little AJAX examples
actually cause Javascript memory leaks. You can search the web to
learn how to handle the resources correctly yourself, but the
libraries like jQuery and YUI that are available do it for you and
seem to eliminate most of the leaks that I've seen. YMMV.

Andrew

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Tim Streater
Re: [PHP] Creating drop-down menus
July 17, 2012 11:50PM
On 17 Jul 2012 at 21:58, Paul M Foster <[email protected]> wrote:

> On Wed, Jul 18, 2012 at 08:45:34AM +1200, James Newman wrote:
>
>> Just to put my 2cents in, you might want to try jQuery if you're going to
>> go down the AJAX road.
>
> JQuery is a LOT of code to include if you're just going to do an AJAX
> call or two. There are examples of doing straight AJAX with Javascript
> on the 'Net. Once you work through them, you find that there's a
> "static" part that you can include in all the files you want to make
> AJAX calls. And then there's the part that deals directly with the data
> you get back from whatever PHP or other script is feeding you data from
> outside the website. That's the part that needs custom work. I *hate*
> Javascript, but I managed to figure it out.

I agree about JQuery. You can look here:

http://www.clothears.org.uk/examples-ajax.php

to see a simple example of how to use AJAX.

--
Cheers -- Tim

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Tedd Sperling
Re: [PHP] Creating drop-down menus
July 19, 2012 07:30PM
On Jul 16, 2012, at 4:16 PM, Ramiro Barrantes <[email protected]> wrote:

> Hello,
>
> I am making an application using PHP/Javascript/mysql and had a question.
>
> Sometimes I need to use javascript to fill a drop down box based on the value of a previous drop down box. However, the information to fill the latter is stored in mysql and can be a lot, what I have been doing is that, using PHP, I create hidden fields with all the possible information that might be needed to fill the second drop down.
>
> For example, the user chooses a bank from a drop down, and then a list of clients is displayed on the following drop down. I use PHP to read all clients from all the banks and put that as hidden fields on the html page. It is very cumbersome.
>
> I do not want to read the database (which changes dynamically) from javascript directly due to confidentiality and because a lot of care has been taken to create the appropriate queries with checks and protect misuse of the information using PHP.
>
> My questions are:
> 1) Do people just normally use hidden fields to store possible information to fill the drop downs?
> 2) any suggestions?
>
> Thanks in advance,
> Ramiro
>


Ramiro:

The subject line of "Creating drop-down menus" is misleading -- here is what a "drop-down menu" is:

http://sperling.com/examples/new-menuh/
http://sperling.com/examples/menuh/

And similarly, a "fly-out menu":

http://sperling.com/examples/menuv/

What you are describing is simply a self-updating selection control, like this:

http://php1.net/a/zipcode-states/

The description and code is there.

To the PHP gang:

As for the discussion re jQuery and such, there's no need -- it was not used in this demo. IOW, no jQuery was harmed. I am not against jQuery, on the contrary I think it's great, but it's not always needed for client-side functionality. As I see it, there is no need for a sledgehammer to drive a thumb tack.

Please realize that all controls (input, textarea, options, selections, checkboxes, radio buttons, multi-options, etc.) can be handled this fashion. This is not your father's limited server-side php, but rather a coupling of both server-side and client-side languages to provide a more desktop-application-like user experience.

Cheers,

tedd


_____________________
tedd@sperling.com
http://sperling.com



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Daniel Brown
Re: [PHP] Creating drop-down menus
July 19, 2012 08:00PM
On Thu, Jul 19, 2012 at 1:25 PM, Tedd Sperling <[email protected]> wrote:
>
> As for the discussion re jQuery and such, there's no need -- it was not used in this demo. IOW, no jQuery was harmed. I am not against jQuery, on the contrary I think it's great, but it's not always needed for client-side functionality. As I see it, there is no need for a sledgehammer to drive a thumb tack.

As an aside on the subject of jQuery, our very own Jay Blanchard
has written a comprehensive book on the topic entitled "Applied
jQuery: Develop and Design":

http://links.parasane.net/92xb

It's one of the very rare (read: two) programming books found on
my shelf. The other is "Jamsa's C/C++ Programmer's Bible" by Kris
Jamsa and Lars Klander. I borrowed it from my brother for reference
when Internet connections wouldn't be available.... perhaps someday
he'll get it back, too.

--
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Tedd Sperling
Re: [PHP] Creating drop-down menus
July 20, 2012 03:40AM
On Jul 19, 2012, at 1:50 PM, Daniel Brown <[email protected]> wrote:
>
> As an aside on the subject of jQuery, our very own Jay Blanchard
> has written a comprehensive book on the topic entitled "Applied
> jQuery: Develop and Design":
>
> http://links.parasane.net/92xb
>

Just bought it -- thanks. I'll add it to my other three jQuery books

Always support the people on this list.

Cheers,

tedd

_____________________
tedd@sperling.com
http://sperling.com




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
tamouse mailing lists
Re: [PHP] Creating drop-down menus
July 20, 2012 04:30PM
On Jul 19, 2012 8:31 PM, "Tedd Sperling" <[email protected]> wrote:
>
> On Jul 19, 2012, at 1:50 PM, Daniel Brown <[email protected]> wrote:
> >
> > As an aside on the subject of jQuery, our very own Jay Blanchard
> > has written a comprehensive book on the topic entitled "Applied
> > jQuery: Develop and Design":
> >
> > http://links.parasane.net/92xb
> >
>
> Just bought it -- thanks. I'll add it to my other three jQuery books
>
> Always support the people on this list.
>
> Cheers,
>
> tedd
>
> _____________________
> tedd@sperling.com
> http://sperling.com
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

I have to ask, is it available in a non-DRMed shook format?
tamouse mailing lists
Re: [PHP] Creating drop-down menus
July 20, 2012 04:30PM
On Jul 20, 2012 9:20 AM, "tamouse mailing lists" <[email protected]>
wrote:
>
>
> On Jul 19, 2012 8:31 PM, "Tedd Sperling" <[email protected]> wrote:
> >
> > On Jul 19, 2012, at 1:50 PM, Daniel Brown <[email protected]> wrote:
> > >
> > > As an aside on the subject of jQuery, our very own Jay Blanchard
> > > has written a comprehensive book on the topic entitled "Applied
> > > jQuery: Develop and Design":
> > >
> > > http://links.parasane.net/92xb
> > >
> >
> > Just bought it -- thanks. I'll add it to my other three jQuery books
> >
> > Always support the people on this list.
> >
> > Cheers,
> >
> > tedd
> >
> > _____________________
> > tedd@sperling.com
> > http://sperling.com
> >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
> I have to ask, is it available in a non-DRMed shook format?

Ok, so shook is what ebook autocorrects to....
Daniel Brown
Re: [PHP] Creating drop-down menus
July 20, 2012 05:00PM
On Fri, Jul 20, 2012 at 10:21 AM, tamouse mailing lists
<[email protected]> wrote:
> On Jul 20, 2012 9:20 AM, "tamouse mailing lists" <[email protected]>
> wrote:
>> On Jul 19, 2012 8:31 PM, "Tedd Sperling" <[email protected]> wrote:
>> > On Jul 19, 2012, at 1:50 PM, Daniel Brown <[email protected]> wrote:
>> > >
>> > > As an aside on the subject of jQuery, our very own Jay Blanchard
>> > > has written a comprehensive book on the topic entitled "Applied
>> > > jQuery: Develop and Design":
>> > >
>> > > http://links.parasane.net/92xb
>> > >
>> >
>> > Just bought it -- thanks. I'll add it to my other three jQuery books
>> >
>> > Always support the people on this list.
>> >
>>
>> I have to ask, is it available in a non-DRMed shook format?
>
> Ok, so shook is what ebook autocorrects to....

Not sure. Jay, can you address Tamara's question?

--
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Sorry, only registered users may post in this forum.

Click here to login