homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Selecting using MYSQL
looking for help in selecting directory levels

10+ Year Member

Msg#: 3679940 posted 11:33 pm on Jun 20, 2008 (gmt 0)


Wondering if anyone can help me here - I use Linux, HTML, PHP and MYSQL in my sites, but unfortunately have a very limited knowledge of javascript.

I have a directory which for example has a top level of:
England, Scotland, Ireland and Wales

Under ALL of those, a sub level of:
Widgets1, Widgets2, Widgets3 etc...

Then, under all of those

Product1, Product2, Product3 etc...

and possibly another level.

I need a javascript program which will access the MYSQL database to present a popup to allow users to select, say 'England'. When they select that, the sublevel will allow them to select a Widget, then once they have done that, can select the Product option.
I then need to get the selected option back into the database/html/php or whatever?

Appreciate this is probably simple stuff, but its just not my area.

Anyony suggest any urls I can look at, or (ideally) code they can post or sticky me with?

IF this can't be done in javascript - any ideas?

Thanks very much.



5+ Year Member

Msg#: 3679940 posted 12:06 am on Jun 21, 2008 (gmt 0)

I'm no expert on this myself, but I don't think JavaScript needs to be used here. I don't think it even can be used (to access a database).

I would do away with the directory method and have the page be a PHP full of if-else statements.

URL structure:

The code would resemble:
IF (the country variable isset in the URL) {
IF (the widget isset in the URL) {
IF (the product isset in the URL) {
display info about the product;
offer a choice of product;
offer a choice of widget;
offer a choice of country;

This way, no worries about client javascript support, no annoying pop-ups, and it's bookmarkable because of the URL query string.

I hope I understood you. If this is misleading or confusing, please post or pm me.


10+ Year Member

Msg#: 3679940 posted 9:43 am on Jun 21, 2008 (gmt 0)

Thanks for the reply febfoo.

I could use something like that (in fact I do).

But what I mean is if the user is on a page, I have a button which says 'choose a new category'

Clicking that displays a javascript (or some other language if it needs to) popup, so the user does not have to leave the current page, that allows choice of top level category.
They choose one and unerneith allows choice of a sub category, choosing that then allows a choice of the bottom level categories (all selected from my MYSQL database).

Clicking OK returns to the html/php page where their choices are now inserted into the screen when the user can select 'GO' and it will take them there.

Any ideas?


5+ Year Member

Msg#: 3679940 posted 4:51 pm on Jun 21, 2008 (gmt 0)

I still like avoiding pop-ups. Just have a part of the page be a div that is hidden/showed by javascript.

That div could contain a PHP-generated javascript. Using PHP, select the categories from the database. Have the PHP write a some kind of javacript offering the choices from the database. My mind is going blank about how exactly to do this, but I'm sure you can figure it out.



WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 3679940 posted 8:04 pm on Jun 21, 2008 (gmt 0)

Any ideas?

When outputting the page, use your PHP to generate your subcategories and lists, and in doing so output the Javascript dynamically and store those lists in Javascript arrays. So when the page loads, you'll have all the elements you need to modify the lists. I don't have any code but it would be something like

<select name="country" onChange="createWidgetList()">

Where createWidgetList uses document.createElement to create the widget list and write it to the page. The widget list would use the same method to create a product list onChange. This of course becomes problematic on extremely long lists.

Doing it this way, you could test for Javascript and if it's not enabled, add a "next" button to submit each select list to the script and regenerate the page using the methods mentioned in the previous post. Best of both worlds, this makes it non-Javascript dependent.

Learn how here [w3schools.com]


10+ Year Member

Msg#: 3679940 posted 8:35 pm on Jun 21, 2008 (gmt 0)

Some good ideas here, thanks for all the advice, very useful, I'm sure I can work with these.

Thanks again, and appologies for the typo on your name Webfoo!



5+ Year Member

Msg#: 3679940 posted 2:13 pm on Jun 22, 2008 (gmt 0)

Not sure if this is what you're looking for but you could populate a list via Ajax. You would need PHP or another database-able coding package to use it though...Good luck!

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved