Forum Moderators: open

Message Too Old, No Replies

onChange event, help

         

ionut radulescu

1:03 pm on Aug 15, 2006 (gmt 0)

10+ Year Member



Hi, I am very new here, and I have a problem; please help me with this problem becouse is very important to me:
I am new in javascript but I like it very much! I have a php page with a <select> option of product's categories and another <select> option with "types" of categories; for exemple if I choose Category: "Computers and Networking" I want Type changes in "CPU, Memory, TFT, Routers etc..." WITHOUT the load of the page! How can I make this?Please help!

Fotiman

4:56 pm on Aug 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you google for dynamic select box, you will find the answer you need. There are plenty of free libraries/toolkits that do this already. But essentially, you want to create an array of Option objects for each list, and then just swap them on when the first list changes.

ionut radulescu

6:31 pm on Aug 15, 2006 (gmt 0)

10+ Year Member



I have a DB with all the types(1) and categories(2);
The selected option queries the DB (MySQL - Server) with 2 tables: (1): 70 entries and (2): ~ 17.000 entries (the tables are InnoDB); if option "1" is selected then <select>2 will queries the DB and changes with the caractheristics of option selected(extract ~ 1200 entries from 17.000);
Thank you!

Fotiman

8:03 pm on Aug 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




I have a DB with all the types(1) and categories(2);
The selected option queries the DB (MySQL - Server) with 2 tables: (1): 70 entries and (2): ~ 17.000 entries (the tables are InnoDB); if option "1" is selected then <select>2 will queries the DB and changes with the caractheristics of option selected(extract ~ 1200 entries from 17.000);

So you're looking for an AJAX solution to populate the 2nd dropdown list. I've not done it myself, but I image it would be something like this:

// 1. Load the page with all options for the first select box (types).
// 2. Create an onchange event handler for this select box. This handler will get the value from the select box and create an AJAX request to the server. The server will get the Categories for that value and return the list.
// 3. When your response comes back from the server, create an array of Option objects from the list and set the array to the options of your 2nd select box.

Wish I could provide more help.